bzip2 command in Linux

Last Updated : 17 Apr, 2026

The bzip2 command is used to compress and decompress files in Linux. It reduces file size by creating compressed .bz2 files, which take less storage than the original files. Uses the Burrows–Wheeler block-sorting algorithm and Huffman coding for compression.

  • Replaces the original file with a .bz2 version by default.
  • Slower decompression time and higher memory usage compared to gzip.
  • Can retain the original file using the -k option.
  • Suitable for storage optimization and data transfer.

Example: Compressing a File While Keeping the Original

Command:

​bzip2 -k file1.txt
  • -k: Keeps the original file intact. Without -k, file1.txt would be removed.

Output:

bz2
Compressing a File While Keeping the Original

Syntax

bzip2 [OPTIONS] filenames ...
  • filenames: One or more files to compress individually.
  • Compressed files are named <original>.bz2.

Commonly Used Options in bzip2

1. Compress a File (-z Option)

The -z option forces compression, though it is the default action of the bzip2 command. When you run this command, the original file is replaced by the compressed version.

Command:

bzip2 -z input.txt

Output:

Compress a File
Compress a File

2. Decompress a File (-d Option)

The -d option is used for decompressing files that were previously compressed using bzip2.

Command:

bzip2 -d input.txt.bz2

Output:

Decompress a File
Decompress a File

3. Integrity Check (-t Option)

If you want to check whether a .bz2 file is corrupted without decompressing it, the -t option comes in handy. It checks the integrity of the file and informs you if it's corrupted.

Command:

bzip2 -t input.txt.bz2

Output:

Integrity Check
Integrity Check

4. Verbose Mode (-v Option)

The -v option enables verbose mode, where the command shows additional information, such as compression ratios and other diagnostics, during the compression process.

Command:

bzip2 -v input.txt

Output:

Verbose Mode
Verbose Mode

Other Available Options

OptionDescription
-h, --helpDisplays the help message and exits.
-L, --licenseDisplays the software version, license terms, and conditions.
-V, --versionDisplays the software version and exits.
-q, --quietSuppresses non-essential warning messages. Critical messages like I/O errors are still displayed.
-f, --forceForces overwriting of output files without confirmation.
Comment

Explore