bzip2 command in Linux/Unix

The bzip2 command in Linux is used for compressing and decompressing files.

  • It is like gzip command but takes a little more time to compress but compresses better.
  • It uses the Burrows-Wheeler block-sorting text compression algorithm and Huffman coding.
  • bzip2 command creates a compressed file with the extension “.bz2”.

Syntax for bzip2 command

bzip2 [OPTIONS] filename

Uses of bzip2 command

Check bzip2 command is already installed or not. To check this just type bzip2 in the terminal.


bzip2 command in linux-unix with examples

Installing bzip2 command

The bzip2 command can be installed using following command

  • For Debian/Ubuntu
sudo apt install bzip2
  • For Contos/RHEL
sudo yum install  bzip2
  • For Fedora
sudo dnf install bzip2

sudo apt install bzip2

bzip2 Help

To get help for bzip2 command and find options available with bzip2 command, Use bzip2 --help command.

bzip2 --help

bzip2 --help


TO check bzzip2 installed version, use command bzip2 --version

bzip2 --version

bzip2 --version

Convert file to bzip2 file

  • For single file

bzip2 command can be used to convert single file or multiple file

bzip2 filename
bzip2 123.txt

bzip2 filename

  • For Multiple file
bzip2 file1 file2 file3 ......
bzip2 abc.txt def.txt

bzip2 file1 file2

  • For files with same extension
bzip2 *.file_extension
bzip2 *.html

bzip2 file-pattern

Convert to bzip2 file without deleting original file

bzip2 -k filename
bzip2 -k 456.txt

bzip2 -k filename

bzip2 -v filename
bzip2 -v 789.txt

bzip2 -v filename


Unzip bzip2 file

bzip2 -d zip_filename
bzip2 -d 123.txt.bz2

bzip2 -d bzip2 file

Check Validity of bzip2 file

bzip2 -t 456.txt.bz2

bzip2 -t filename

bzip2 -v -t 456.txt.bz2

bzip2 -v -t filename

bzip2 -t 677.bz2

bzip2 -t zipfile-other

bzip2 -f 456.txt

bzip2 -f filename

bzip2 -cd 123.txt.bz2

bzip2 -cd bzip2-file

bzip2 -q -t 677.bz2

bzip2 -q -t other-zip2file

Sharing is Caring
Scroll to Top