bzip2 Command
Beginner Compression & Archives man(1)Compress files using Burrows-Wheeler block sorting
👁 9 views
📅 Updated: Mar 15, 2026
SYNTAX
bzip2 [OPTION]... [FILE]...
What Does bzip2 Do?
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.
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.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -d | Decompress | bzip2 -d file.bz2 |
| -k | Keep original file | bzip2 -k largefile.txt |
| -1 to -9 | Compression level | bzip2 -9 data.bin |
| -z | Force compression | bzip2 -z file |
| -v | Verbose | bzip2 -v file.txt |
| -c | Write to stdout | bzip2 -c file > file.bz2 |
Practical Examples
#1 Compress a file
Compresses the file, replacing it with large_dump.sql.bz2.
$ bzip2 large_dump.sql#2 Decompress
Decompresses back to the original. Or use bunzip2.
$ bzip2 -d file.bz2#3 Keep original
Compresses while keeping the original file.
$ bzip2 -k data.csv#4 Create tar.bz2
Creates a bzip2-compressed tar archive.
$ tar cjf archive.tar.bz2 /data/#5 Maximum compression
Uses best compression for the smallest output.
$ bzip2 -9 distribution.tar#6 Stream compression
Compresses database dump on-the-fly.
$ mysqldump mydb | bzip2 > backup.sql.bz2Tips & Best Practices
gzip vs bzip2 vs xz: Speed: gzip > bzip2 > xz. Compression: xz > bzip2 > gzip. For daily backups use gzip. For distribution use xz.
Slow decompression: bzip2 decompression is also slower than gzip. For files accessed frequently, gzip may be more practical.
pbzip2 for parallel: Install pbzip2 for multi-threaded bzip2 compression. Dramatically faster on multi-core systems.
Frequently Asked Questions
When should I use bzip2 instead of gzip?
When file size matters more than speed — bzip2 gives 10-20% better compression. For daily use, gzip is usually better.
How do I decompress a .bz2 file?
bzip2 -d file.bz2 or bunzip2 file.bz2. Both work identically.
How do I compress a directory with bzip2?
bzip2 only handles single files. Use tar cjf archive.tar.bz2 directory/ for directories.
Related Commands
More Compression & Archives Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →