Bzip2 is a popular compression algorithm used to compress and extract files & folders using tar command, just like gzip. It is also available as a standalone tool. bzip files have .bz2 and .tar.bz2 file extensions. In this article, we will look at how to extract .bz2 file in Linux.
How to Extract .bz2 File in Linux
Here are the steps to extract .bz2 file in Linux. You can decompress .bz2 file using tar command or using bzip2 command.
If you do not have bzip2 command on your system, you can easily install it with any of the following commands.
$ sudo apt install bzip2 [On Debian/Ubuntu] $ sudo yum install bzip2 [On CentOS/RHEL]
Also read : How to View Hidden Files in Linux
Extract .bz2 file using Tar command
Tar is present in almost every Linux system by default. Here is the command to decompress .bz2 file using tar utility.
$ sudo tar -xf <filename> [destination]
In the above command, we use -xf options to extract .bz2 file. You also need to provide filename of your archive. You may optionally provide the destination where you want the file content to be extracted. If you do not provide destination folder, then .bz2 file will be extracted in your present working directory.
Here is an example
$ sudo tar -xf test.bz2 /home/ubuntu
Also read : How to Merge Two Dictionaries in Python
Extract .bz2 file using bzip2 command
Here is the command to easily decompress bzip2 file.
$ sudo bzip2 -d <filename>
Here is an example
$ sudo bzip2 -d /home/ubuntu/test.bz2
Please note, tar command is present in almost every Linux system by default, but bzip2 may not be installed in some Linux distributions.
That’s it. As you can see, it is very easy to extract and decompress .bz2 file in Linux.
Also read : How to Run PHP Scripts Automatically
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.