Linux Command: bzip2
Compress files using Burrows-Wheeler block sorting
bzip2 compresses files using the Burrows-Wheeler algorithm, typically producing better compression than gzip but running slower. Compressed files get the .bz2 extension. bzip2 offers significantly better compression ratios than gzip, typically 10-20% smaller files, at the cost of being 2-3x slower. It is commonly used for distributing large files where download size matters more than compression speed. bzip2 works on single files only. For directories, use tar cjf archive.tar.bz2 to combine tar archiving with bzip2 compression.
Syntax
bzip2 [OPTION]... [FILE]...Key Options
-dโ Decompress-kโ Keep original file-1 to -9โ Compression level-zโ Force compression-vโ Verbose-cโ Write to stdout
Examples
Compress a file
bzip2 large_dump.sqlDecompress
bzip2 -d file.bz2Keep original
bzip2 -k data.csvPro Tips
- Speed: gzip > bzip2 > xz. Compression: xz > bzip2 > gzip. For daily backups use gzip. For distribution use xz.
- bzip2 decompression is also slower than gzip. For files accessed frequently, gzip may be more practical.
- Install pbzip2 for multi-threaded bzip2 compression. Dramatically faster on multi-core systems.
Learn more: Full bzip2 reference โ