How to Compress and Decompress a .bz2 File in Linux

To compress a file(s), is to significantly decrease the size of the file(s) by encoding data in the file(s) using less bits, and it is normally a useful practice during backup and transfer of a file(s) over a network. On the other hand, decompressing a file(s) means restoring data in the file(s) to its original state.

Suggested Read: Learn Linux ‘tar’ Command with This 18 Examples

There are several file compression and decompression tools available in Linux such as gzip, 7-zip, Lrzip, PeaZip and many more.

In this tutorial, we will look at how to compress and decompress .bz2 files using the bzip2 tool in Linux.

Bzip2 is a well known compression tool and it’s available on most if not all the major Linux distributions, you can use the appropriate command for your distribution to install it.

$ sudo apt install bzip2     [On Debian/Ubuntu] 
$ sudo yum install  bzip2    [On CentOS/RHEL]
$ sudo dnf install bzip2     [On Fedora 22+]

The conventional syntax of using bzip2 is:

$ bzip2 option(s) filenames 

How to Use “bzip2” to Compress Files in Linux

You can compress a file as below, where the flag -z enables file compression:

$ bzip2 filename
$ bzip2 -z filename

To compress a .tar file, use the command format:

$ bzip2 -z backup.tar

Important: By default, bzip2 deletes the input files during compression or decompression, to keep the input files, use the -k or --keep option.

In addition, the -f or --force flag will force bzip2 to overwrite an existing output file.

------ To keep input file  ------
$ bzip2 -zk filename
$ bzip2 -zk backup.tar

You can as well set the block size to 100k upto 900k, using -1 or --fast to -9 or –best as shown in the below examples:

$ bzip2 -k1  Etcher-linux-x64.AppImage
$ ls -lh  Etcher-linux-x64.AppImage.bz2 
$ bzip2 -k9  Etcher-linux-x64.AppImage 
$ bzip2 -kf9  Etcher-linux-x64.AppImage 
$ ls -lh Etcher-linux-x64.AppImage.bz2 

The screenshot below shows how to use options to keep the input file, force bzip2 to overwrite an output file and set the block size during compression.

Compress Files Using bzip2 in Linux

Compress Files Using bzip2 in Linux

How to Use “bzip2” to Decompress Files in Linux

To decompress a .bz2 file, make use of the -d or --decompress option like so:

$ bzip2 -d filename.bz2

Note: The file must end with a .bz2 extension for the command above to work.

$ bzip2 -vd Etcher-linux-x64.AppImage.bz2 
$ bzip2 -vfd Etcher-linux-x64.AppImage.bz2 
$ ls -l Etcher-linux-x64.AppImage 
Decompress bzip2 File in Linux

Decompress bzip2 File in Linux

To view the bzip2 help page and man page, type the command below:

$ bzip2  -h
$ man bzip2

Lastly, with the simple elaborations above, I believe you are now capable of compressing and decompressing .bz2 files using the bzip2 tool in Linux. However, for any questions or feedback, reach us using the comment section below.

Importantly, you may want to go over a few important Tar command examples in Linux so as to learn using the tar utility to create compressed archive files.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

2 Responses

  1. Tomek says:

    What does mean -v?

    • Aaron Kili says:


      The flag -v means verbose mode, where the compression ratio of each file is processed and displayed to the user. You can look through the bzip2 man page for more details.

Leave a Reply to Tomek Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.