A “tar.bz2” file is a compressed archive file created using the tar command in Unix/Linux and the bzip2 compression algorithm. It is commonly used for distributing large files or groups of files as a single archive, which is smaller in size compared to the original files, making it easier to transfer and manage.
The tar command is used to create an archive of multiple files or directories and the bzip2 compression algorithm is used to reduce the size of the archive. The resulting archive file has a .tar.bz2 extension and can be unpacked using the tar command with the -j option.
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 file
- Command to list the content of tar.bz2 without extracting it
How to Unzip
You can use Linux tar command with option
-j to extract bz2 file. As this is a also tar compressed file, You also need to use
-x command line option.
So we can use
-xjf options with the tar command to extract a
tar -xjf filename.tar.bz2
The above command will extract
tar.bz2 file content in current directory.
To extract files in a defend location, use
-C option followed by the destination directory.
tar -xvjf filename.tar.bz2 -C /opt
Now all the files will be extracted under /opt directory.
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.
For example, to create a backup of your web server directory, execute:
tar -cjf backup.tar.bz2 /var/www/html
The above command will compress all the files available under /var/www/html directory and create backup.tar.bz2 compressed file in current directory.
How to list tar.bz2 content without extract
You never need to extract a archive file to just view the file content. Use
-v (verbose) command line option to list archive file content only.
tar -tvjf backup.tar.bz2
Outputdrwxr-xr-x root/root 0 2023-02-01 11:54 var/www/html/ drwxr-xr-x root/root 0 2023-02-01 11:54 var/www/html/static/ drwxr-xr-x root/root 0 2023-02-01 11:55 var/www/html/static/js/ -rw-r--r-- root/root 14150 2023-02-01 11:55 var/www/html/static/js/main.js drwxr-xr-x root/root 0 2023-02-01 11:55 var/www/html/static/css/ -rw-r--r-- root/root 14149 2023-02-01 11:55 var/www/html/static/css/main.css -rw-r--r-- root/root 10701 2023-01-31 11:01 var/www/html/index.html
An archive file are useful for creating backups, making bundle of files and save disk space. 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 extracting it.
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