Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Extract (Unzip) Tar Bz2 File - DesignLinux

Jul 24 2020
designlinux 0 Comments
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.

Related

Tags: tar, terminal

How to make a POST request with cURL

Prev Post

How to Change the SFTP Port

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 259
  • 614,631

DesignLinux.com © All rights reserved

Go to mobile version