JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to Unzip Bzip2 Files in Linux Terminal

Author:JIYIK Last Updated:2025/04/05 Views:

taris a command line tool that allows us to create and decompress tarfiles. It supports most compression programs, such as gzip, lzip, bzip2, lzma, , lzop, xzand compress. bzip2Files compressed with end with .tar.bz2or .tbz2. We can use tarthe command to compress and decompress files .tar.bz2in and .tbz2formats.

Unzip a .tar.bz2file

We use the --extractor -xoption, followed by -fthe option, and then specify the file to extract.

tar -xf compressed.tar.bz2

It decompresses compressed files by detecting the type of compression used compressed.tar.bz2. We can also use the same command to decompress files compressed with other algorithms.

For most of the Linux users, tarthe tool is installed by default during installation. For Windows users, we have a 7-ziptool called to unzip bz2files.

If we want to know some information about the decompression, we can use -vthe -p option.

tar -xvf compressed.tar.bz2

It will print the names of all unpacked files in the terminal.

By default, the contents of the compressed file will be extracted in the current working directory. If you want to extract the files in a specific directory, we can use the --directoryor -Coption to specify the path where the files need to be extracted.

tar -xf compressed.tar.bz2 -C /home/Extracted_Files

It will extract the compressed files in the current working directory compressed.tar.bz2to the directory homeinside Extracted_files.

List tar.bz2the contents of a file

To list the contents of a tar.bz2 file, we use the -p or -p option tarof the tar.bz2 command .--list-t

tar -tf compressed.tar.bz2

Output:

Blues/hey.mp3
1.mp3
2.mp3

It displays compressed.tar.bz2all the contents of the file.

To get more details about the content like owner, file size, timestamp, we use the -w or -w options tarof the command .--verbose-v

tar -tvf compressed.tar.bz2

Extract specific files and directories from a compressed file

In order to extract only specific files and directories from a compressed file, we list the names of the files and directories to be extracted with spaces after the compressed file.

tar -xf compressed.tar.bz2 1.mp3 2.mp3

1.mp3It will only extract the and files from the compressed file 2.mp3.

While specifying the files, we have to use the exact path to unzip the files as tarshown in the command and use the --listor -toption.

tar -xf compressed.tar.bz2 jazz Rock

jazzIt will only extract the and directories from the archive Rock.

If the file we specify does not exist, we will get an output saying that the file was not found.

tar -xf compressed.tar.bz2 rolling.jpeg。

Here, if the file rolling.jpegdoes not exist, we will get the following error.

tar: rolling.jpeg: Not found in archive
tar: Exiting with failure status due to previous errors

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

11 Examples of tar Command in UNIX and Linux

Publish Date:2025/04/06 Views:165 Category:OPERATING SYSTEM

The tar command in UNIX or Linux tar is one of the important commands that provides archiving capabilities in UNIX. We can create compressed or uncompressed archive files using gzip or bzip2 tar using UNIX commands . In this UNIX command tu

Open links in new tabs with React

Publish Date:2025/03/13 Views:79 Category:React

To open a link in a new tab in React, use an a element and set its `target` attribute to _blank, for example. A _blank value indicates that the resource is loaded into the new tab.

How to set target=_blank in React

Publish Date:2025/03/13 Views:203 Category:React

To set the target attribute of an element to _blank in React, use an anchor element and set the rel attribute, for example . The _blank value indicates that the resource is loaded in a new tab.

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial