A tar.bz2
file is compressed file using Tar with a Burrows-Wheeler (BZ2) compression algorithm. These file will have the extension “.tar.bz2
“. Most commonly, this file format is used for distributing software packages on Unix based operating systems.
We can unzip a .tar.bz2
file using Linux tar command. In this tutorial, you will learn the followings:
- How to Unzip tar.bz2 file
- How to Create tar.bz2 compressed files
- Command to list tar.bz2 content without extract
How to Unzip tar.bz2
file
You can use Linux tar command with option -j
to extract bz2 file. As this is a Tar compressed file, You also need to use -x
command line option.
So use -xv
with tar command to extract a .tar.bz2 file:
tar -xvjf filename.tar.bz2
The above command will extract tar.bz2
file content in current directory.
To extract files in other directory, use -C
option with destination directory.
tar -xvjf filename.tar.bz2 -C /opt
How to create tar.bz2 file
The tar command uses -c
to create a compressed Tar archive file. You can also use -j
to create a tar.bz2
archive file.
tar -cjf filename.tar.bz2 *.log
How to list tar.bz2 content without extract
You never need to extract a archive file to just view the file content. Use -t
with -v
(verbose) command line option to list archive file content only.
tar -tvzf filename.tar.bz2
-rw------- root/root 863287 2014-08-14 17:35:58 anaconda.log
-rw------- root/root 0 2014-12-29 02:17:27 boot.log
-rw-r--r-- root/root 0 2014-12-29 02:17:26 kdm.log
-rw-r--r-- root/root 25643 2014-12-29 01:12:35 Xorg.0.log
-rw-r--r-- root/root 11380 2014-11-24 17:35:39 yum.log
Conclusion
In this tutorial, you have learned how to extract a .tar.bz2
file using command line. Additionally, you learned to create .tar.bz2
file or list files without extract.
1 Comment
Thanks for sharing the good details. If you still get an error, even after trying out the above steps – please do the below.
#yum install bzip2 -y