• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Extract (Unzip) Tar Bz2 File

Written by Admin, Updated On July 21, 2020
tar, terminal
Extract tar.bz2 file

This tutorial explains how to extract (or unzip) tar.bz2 and tbz2 archives using the tar command. The tar command is used to make and extract tar archives. Compression programs such as gzip, bzip2, lzip, lzma, lzop, xz and compress are supporting by it.

Extract tar.bz2 File#

By default the tar utility comes pre-installed in most Linux distro and macOS. To extract a tar.bz2 file, use the --extract (-x) option and specify the archive file name after the -f option:

tar -xf archive.tar.bz2

The tar command consider the compression type automatically and extracts the archive. The same command can be used to extract tar archives compressed with other algorithms such as .tar.gz or or .tar.xz .

To extract the file using File manager, simply right click on the file you want to extract and select “Extract”. If you are using Windows OS you will need a tool named 7zip to extract tar.bz2 files.

To show the verbose output use the -v option. This option tells tar to display the names of the files being extracted on the terminal.

tar -xvf archive.tar.bz2

The tar will extract the archive contents or files in the current working directory. If you would like to extract the archive files in a specific directory you should use --directory (-C):

For instance, to extract the archive contents to the /home/tecnstuff/files directory, you would type:

tar -xf test.tar.bz2 -C /home/tecnstuff/files

Extracting Specific Files from a tar.bz2 File#

To extract a specific file from a tar.bz2 file, you should give the file name which you want to extract. You also can extract multiple files by space-separated list of file names:

tar -xf test.tar.bz2 filename1 filename2

Make sure you should give their exact names with the path, you can print using the --list (-t) option.

It’s a same procedure as files to extract one or more directories from an archive:

tar -xf test.tar.bz2 dir_name1 dir_name2

It will show following error message if the given file name is not exists in the archive:

tar -xf test.tar.bz2 tns.txt
tar: tns.txt: Not found in archive
tar: Exiting with failure status due to previous errors

You also can extract the files using --wildcards option based on a wildcard pattern. The pattern must be quoted to prevent the shell from interpreting it.

For example, to extract only .php files, you would use :

tar -xf test.tar.bz2 --wildcards '*.php'

Listing tar.bz2 File#

To list the content of a tar.bz2 file, use the --list (-t) option:

tar -tf test.tar.bz2

The output will look something like this:

filename1
filename2
filename3

If you add the --verbose (-v) option, tar will print more information, such as owner, file size, timestamp, etc.:

tar -tvf test.tar.bz2
-rw-r--r-- tecnstuff/users       0 2020-02-02 01:59 filename1
-rw-r--r-- tecnstuff/users       0 2020-02-02 01:59 filename2
-rw-r--r-- tecnstuff/users       0 2020-02-02 01:59 filename3

Conclusion#

tar.bz2 file is a Tar archive compressed with Bzip2. To extract a tar.bz2 file, use the tar -xf command followed by the archive name.

If you have any questions or feedback, feel free to leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install TensorFlow on CentOS 8
Next Article   How to Install Memcached on Ubuntu 20.04

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook