How to Unzip Bzip2 Files in Linux Terminal
tar
is a command line tool that allows us to create and decompress tar
files. It supports most compression programs, such as gzip
, lzip
, bzip2
, lzma
, , lzop
, xz
and compress
. bzip2
Files compressed with end with .tar.bz2
or .tbz2
. We can use tar
the command to compress and decompress files .tar.bz2
in and .tbz2
formats.
Unzip a .tar.bz2
file
We use the --extract
or -x
option, followed by -f
the 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, tar
the tool is installed by default during installation. For Windows users, we have a 7-zip
tool called to unzip bz2
files.
If we want to know some information about the decompression, we can use -v
the -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 --directory
or -C
option 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.bz2
to the directory home
inside Extracted_files
.
List tar.bz2
the contents of a file
To list the contents of a tar.bz2 file, we use the -p or -p option tar
of the tar.bz2 command .--list
-t
tar -tf compressed.tar.bz2
Output:
Blues/hey.mp3
1.mp3
2.mp3
It displays compressed.tar.bz2
all the contents of the file.
To get more details about the content like owner, file size, timestamp, we use the -w or -w options tar
of 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.mp3
It 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 tar
shown in the command and use the --list
or -t
option.
tar -xf compressed.tar.bz2 jazz Rock
jazz
It 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.jpeg
does 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.
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
Fix createRoot(...): Target container is not a DOM element error in React
Publish Date:2025/03/16 Views:61 Category:React
-
There are several reasons for the error “createRoot(...): Target container is not a DOM element” in React: Passing an incorrect id to the document.getElementById() method.
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.
Java 错误 Error:Java: Javactask: Source Release 1.8 Requires Target Release 1.8
Publish Date:2023/07/14 Views:278 Category:Java
-
在使用IntelliJ for Java时,无法编译Java程序是一个常见的问题。 本教程提供了此错误的解决方案。Error:Java: Javactask: Source Release 1.8 Requires Target Release 1.8 错误
Java 错误 SunCertPathBuilderException: Unable to Find Valid Certification Path
Publish Date:2023/07/11 Views:623 Category:Java
-
本篇文章将讨论 unable to find valid certification path to requested target 潜在原因及其在 Java 中的解决方案。Java中的sun.security.provider.certpath.SunCertPathBuilderException是什么
Python 错误 ValueError: Classification Metrics Can't Handle a Mix of Multiclass
Publish Date:2023/05/17 Views:1424 Category:Python
-
当您在 sklearn.metrics.accuracy_score() 函数中提供无效数组时,会出现错误 ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets。 由于准确度分数是一种分类指标,因此当您
如何在 Linux 终端解压 Bzip2 文件
Publish Date:2023/03/17 Views:124 Category:操作系统
-
我们可以使用 tar 命令来压缩和解压.tar.bz2 和.tbz2 格式的文件。