bzip2(1)
Compress or decompress files using the Burrows-Wheeler block-sorting text compression algorithm.
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
| Flag | What it does |
|---|---|
-d, --decompress | Decompress files (or use bunzip2) |
-k, --keep | Keep input files instead of deleting them after compression |
-f, --force | Overwrite existing output files without prompting |
-v, --verbose | Print compression ratios and filenames for each file processed |
-q, --quiet | Suppress warning messages and non-essential output |
-c, --stdout | Write output to standard output; original files remain unchanged |
-1 to -9 | Set block size in 100-byte increments (1=smallest, 9=best; default 9) |
-s, --small | Use minimal memory when decompressing (slower) |
-t, --test | Test integrity of compressed files without decompressing |
--best | Alias for -9 (best compression) |
--fast | Alias for -1 (fastest compression) |
Examples
Compress largefile.txt to largefile.txt.bz2 and remove the original
bzip2 largefile.txtCompress largefile.txt to largefile.txt.bz2 but keep the original file
bzip2 -k largefile.txtDecompress largefile.txt.bz2 back to largefile.txt
bzip2 -d largefile.txt.bz2Compress logfile through a pipe and write to logfile.bz2
cat logfile | bzip2 -c > logfile.bz2Fast compression of all .txt files with verbose output showing ratios
bzip2 -v -1 *.txtTest the integrity of a compressed file without extracting it
bzip2 -t largefile.txt.bz2Compress 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