bzip2
The bzip2 command is a file compression tool that uses the Burrows-Wheeler block sorting text compression algorithm and Huffman coding. It compresses files more tightly than gzip but less so than xz.
Basic Syntax
bzip2 [OPTION]... [FILE]...
Common Options
| Option | Description |
|---|---|
-d, --decompress | Force decompression. |
-k, --keep | Keep (don't delete) input files. |
-z, --compress | Force compression. |
-1 to -9 | Set block size to 100k .. 900k when compressing (default is 900k). |
Real-world Examples
-
Compress a file (replaces file with
file.bz2):bzip2 access.log -
Compress a file and keep the original:
bzip2 -k access.log -
Decompress a
.bz2file:bzip2 -d archive.tar.bz2(Alternatively, use
bunzip2 archive.tar.bz2) -
Compress with the fastest but least efficient mode:
bzip2 -1 large_file.img