How to Extract (Unzip) Tar Bz2 File

By 

Updated on

5 min read

Unzip Tar Bz2 File

The tar command lets you create and extract tar archives. It supports a wide range of compression formats, including gzip, bzip2, lzip, lzma, lzop, xz, and compress.

Bzip2 is a common compression algorithm for tar files. By convention, a tar archive compressed with bzip2 ends with .tar.bz2 or .tbz2.

This guide shows how to extract (unzip) .tar.bz2 and .tbz2 files with tar.

Extract a tar.bz2 (.tbz2) Archive

The tar utility is pre-installed by default on most Linux distributions and macOS.

To extract a tar.bz2 file, use the --extract (-x) option and specify the archive file name after the -f option:

Terminal
tar -xf archive.tar.bz2

The tar command auto-detects the compression type and extracts the archive. The same command works for other formats such as .tar.gz and .tar.xz .

The -v option makes the output verbose and prints the names of files as they are extracted.

Terminal
tar -xvf archive.tar.bz2

By default, tar extracts into the current working directory . Use the --directory (-C) option to unpack the archive elsewhere.

For instance, to extract the archive contents to the /home/linuxize/files directory, you can use the following command:

Terminal
tar -xf archive.tar.bz2 -C /home/linuxize/files

If you prefer a GUI, most file managers let you right-click and choose “Extract.”

Extracting Specific Files from a tar.bz2 File

To extract specific files from a tar.bz2 archive, include a space-separated list of file names after the archive name:

Terminal
tar -xf archive.tar.bz2 file1 file2

When extracting files, you must provide their exact names along with the path, as listed by tar --list (tar -t).

To extract one or more directories from an archive, you can follow the same process as extracting individual files:

Terminal
tar -xf archive.tar.bz2 dir1 dir2

If you attempt to extract a file that does not exist in the archive, an error message similar to the following will be shown:

Terminal
tar -xf archive.tar.bz2 README
output
tar: README: Not found in archive
tar: Exiting with failure status due to previous errors

You can also extract files from a tar.bz2 file based on a wildcard pattern, by using the --wildcards option and quoting the pattern to prevent the shell from interpreting it.

For example, to extract files whose names end in .md (Markdown files), you would use:

Terminal
tar -xf archive.tar.bz2 --wildcards '*.md'

Extract tar.bz2 from stdin

When extracting a compressed tar.bz2 file by reading the archive from standard input (usually through piping), you must specify the decompression option. The -j option tells tar that the file is compressed with bzip2.

In the following example we are downloading the PHP source using the wget command and piping its output to the tar command:

Terminal
wget -c https://www.php.net/distributions/php-8.4.2.tar.bz2 -O - | sudo tar -xj

If you do not specify a decompression option, tar will indicate which option you should use:

output
tar: Archive is compressed. Use -j option
tar: Error is not recoverable: exiting now

List tar.bz2 Contents

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

Terminal
tar -tf archive.tar.bz2

The output will look something like this:

output
file1
file2
file3

If you add the --verbose (-v) option, tar will print additional information such as file permissions, ownership, size, and timestamp:

Terminal
tar -tvf archive.tar.bz2
output
-rw-r--r-- linuxize/users       0 2026-01-15 01:19 file1
-rw-r--r-- linuxize/users       0 2026-01-15 01:19 file2
-rw-r--r-- linuxize/users       0 2026-01-15 01:19 file3

Extracting and Preserving Permissions

By default, tar preserves file permissions when extracting. If you need to explicitly preserve permissions (useful when running as root), use the -p option:

Terminal
tar -xpf archive.tar.bz2

This preserves the original permissions, ownership, and timestamps.

Handle Existing Files

When extracting, tar will overwrite existing files by default. To skip files that already exist, use the --skip-old-files option:

Terminal
tar -xf archive.tar.bz2 --skip-old-files

To overwrite files only if they are older than the archive contents:

Terminal
tar -xf archive.tar.bz2 --keep-newer-files

Quick Reference

TaskCommand
Extract tar.bz2tar -xf archive.tar.bz2
Extract with verbosetar -xvf archive.tar.bz2
Extract to directorytar -xf archive.tar.bz2 -C /path/to/dir
Extract specific filestar -xf archive.tar.bz2 file1 file2
Extract with wildcardtar -xf archive.tar.bz2 --wildcards '*.md'
Extract .tbz2tar -xf archive.tbz2
List contentstar -tf archive.tar.bz2
List with detailstar -tvf archive.tar.bz2
Preserve permissionstar -xpf archive.tar.bz2

FAQ

What is the difference between tar.bz2 and tar.gz?
Both are tar archives compressed with different algorithms. bzip2 typically produces smaller files than gzip, but compression and decompression are slower. The extraction command is the same: tar -xf.

What is the difference between tar.bz2 and tar.xz?
xz uses LZMA2 and generally achieves better compression than bzip2, but is slower to compress. For extraction speed, the difference is small. Both use the same tar -xf command to extract.

Do I need to install bzip2 to extract tar.bz2 files?
On most Linux distributions, bzip2 is pre-installed. If tar reports that bzip2 support is missing, install it with sudo apt install bzip2 on Debian/Ubuntu or sudo dnf install bzip2 on Fedora/RHEL.

What does the -j flag do?
The -j flag tells tar to decompress using bzip2. You only need it when reading from stdin (piping). When extracting a file from disk, tar auto-detects the compression type.

How do I create a tar.bz2 archive?
Use tar -cjf archive.tar.bz2 file1 file2 dir1. The -c flag creates the archive, and -j compresses it with bzip2. For more details, see our guide on creating tar archives .

Conclusion

We covered how to extract tar.bz2 files including extracting to specific directories, extracting specific files, and listing archive contents.

For more information on creating tar archives, see our guide on creating tar archives . You may also want to check out guides for tar.gz and tar.xz files.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page