bzip2 command in Linux (original) (raw)

Last Updated : 12 May, 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.

Example: Compressing a File While Keeping the Original

**Command:

​bzip2 -k file1.txt

**Output:

bz2

Compressing a File While Keeping the Original

Syntax

bzip2 [OPTIONS] filenames ...

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

Option Description
-h, --help Displays the help message and exits.
-L, --license Displays the software version, license terms, and conditions.
-V, --version Displays the software version and exits.
-q, --quiet Suppresses non-essential warning messages. Critical messages like I/O errors are still displayed.
-f, --force Forces overwriting of output files without confirmation.