$linuxjunkies
>

bzip2(1)

Compress or decompress files using the Burrows-Wheeler block-sorting text compression algorithm.

UbuntuDebianFedoraArch

Synopsis

bzip2 [OPTION]... [FILE]...

Description

bzip2 compresses files using the Burrows-Wheeler block-sorting compression algorithm and Huffman coding. Compression is generally superior to that of gzip, but slower. By default, bzip2 replaces each input file with a compressed version named filename.bz2.

If no files are specified, bzip2 reads from standard input and writes to standard output. This makes it suitable for use in pipes.

bzip2 maintains file permissions and modification times, and can recover from partial damage in compressed files.

Common options

FlagWhat it does
-d, --decompressDecompress files (or use bunzip2)
-k, --keepKeep input files instead of deleting them after compression
-f, --forceOverwrite existing output files without prompting
-v, --verbosePrint compression ratios and filenames for each file processed
-q, --quietSuppress warning messages and non-essential output
-c, --stdoutWrite output to standard output; original files remain unchanged
-1 to -9Set block size in 100-byte increments (1=smallest, 9=best; default 9)
-s, --smallUse minimal memory when decompressing (slower)
-t, --testTest integrity of compressed files without decompressing
--bestAlias for -9 (best compression)
--fastAlias for -1 (fastest compression)

Examples

Compress largefile.txt to largefile.txt.bz2 and remove the original

bzip2 largefile.txt

Compress largefile.txt to largefile.txt.bz2 but keep the original file

bzip2 -k largefile.txt

Decompress largefile.txt.bz2 back to largefile.txt

bzip2 -d largefile.txt.bz2

Compress logfile through a pipe and write to logfile.bz2

cat logfile | bzip2 -c > logfile.bz2

Fast compression of all .txt files with verbose output showing ratios

bzip2 -v -1 *.txt

Test the integrity of a compressed file without extracting it

bzip2 -t largefile.txt.bz2

Compress locally, transfer over SSH, and decompress remotely

bzip2 -c file.txt | ssh user@host 'bzip2 -d > file.txt'

Best compression ratio on bigfile.log, overwriting any existing .bz2 file

bzip2 -9 -f bigfile.log

Related commands