bzip2
file compressionlinux
The bzip2 command is one of the most frequently used commands in Linux/Unix-like operating systems. bzip2 The bzip2 command compresses files using the Burrows-Wheeler block sorting text compression algorithm and Huffman coding. It generally achieves better compression than gzip but is slower.
Quick Reference
Command Name:
bzip2
Category:
file compression
Platform:
linux
Basic Usage:
bzip2 [options] [arguments]
Common Use Cases
Syntax
bzip2 [options] [filenames...] bunzip2 [options] [filenames...]
Options
Option | Description |
---|---|
-c, --stdout | Write to standard output and keep original files |
-d, --decompress | Force decompression (same as using bunzip2) |
-z, --compress | Force compression (default action) |
-t, --test | Test compressed file integrity |
-f, --force | Overwrite existing output files |
-k, --keep | Keep (don't delete) input files during compression/decompression |
-s, --small | Reduce memory usage (at the expense of compression ratio) |
-q, --quiet | Suppress non-error messages |
-v, --verbose | Show compression ratio for each file processed |
-1 to -9 | Set compression level: 1=fastest (less compression), 9=best (slowest) |
--fast | Same as -1 (fastest compression) |
--best | Same as -9 (best compression) |
-L, --license | Display software license |
-V, --version | Display version number |
-h, --help | Display help message |
Examples
How to Use These Examples
The examples below show common ways to use the bzip2
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
#
# Compress a file but keep the original file
bzip2 -k filename.txt
# Creates filename.txt.bz2 and keeps filename.txtBasic Examples:
# Compress a file (original file is replaced by compressed version) bzip2 filename.txt # Creates filename.txt.bz2 and removes filename.txt
Advanced Examples:
# Compress multiple files at once bzip2 file1.txt file2.txt file3.txt