• 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 Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP on Debian 10
    How to Install GIMP 2.10 on Debian 10 December 27, 2020
  • How to Install GIMP 2.10 on CentOS 8
    How to Install GIMP 2.10 on CentOS 8 December 30, 2020
© 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