How to Extract (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, zstd, 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, and how to decompress plain .bz2 files.
Quick Reference
For a printable quick reference, see the tar cheatsheet .
| Task | Command |
|---|---|
| Extract tar.bz2 | tar -xf archive.tar.bz2 |
| Extract with verbose | tar -xvf archive.tar.bz2 |
| Extract to directory | tar -xf archive.tar.bz2 -C /path/to/dir |
| Extract specific files | tar -xf archive.tar.bz2 file1 file2 |
| Extract with wildcard | tar -xf archive.tar.bz2 --wildcards '*.md' |
| Extract .tbz2 | tar -xf archive.tbz2 |
| Extract from stdin | wget -O - URL | tar -xj |
| List contents | tar -tf archive.tar.bz2 |
| List with details | tar -tvf archive.tar.bz2 |
| Preserve permissions | tar -xpf archive.tar.bz2 |
| Decompress a plain .bz2 file | bunzip2 file.bz2 |
| Decompress and keep the .bz2 file | bzip2 -dk file.bz2 |
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:
tar -xf archive.tar.bz2The 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.
tar -xvf archive.tar.bz2By 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:
tar -xf archive.tar.bz2 -C /home/linuxize/filesThe target directory must already exist. If it does not, tar stops with a Cannot open: No such file or directory error.
If you prefer a GUI, most file managers let you right-click and choose “Extract.”
Extracting Plain .bz2 Files
The bzip2 program compresses one file at a time. It does not bundle files the way tar does. A plain .bz2 file, such as a compressed log or a database dump, holds a single file. tar cannot unpack it.
To check whether a .bz2 file holds a tar archive, decompress it to standard output and pass the result to the file
command:
bzip2 -dc backup.bz2 | file -/dev/stdin: POSIX tar archive (GNU)POSIX tar archive in the output means the file is a tar archive without .tar in its name. You can extract it with tar -xf backup.bz2. Any other file type means you have a single compressed file.
To decompress a plain .bz2 file, use the bunzip2 command:
bunzip2 notes.txt.bz2The command writes notes.txt and removes notes.txt.bz2 once decompression succeeds. Running bzip2 with the --decompress (-d) option does the same thing:
bzip2 -d notes.txt.bz2To keep the compressed file, add the --keep (-k) option:
bzip2 -dk notes.txt.bz2If notes.txt already exists, bunzip2 refuses to overwrite it:
bunzip2: Output file notes.txt already exists.To replace the existing file, add the --force (-f) option. Otherwise, rename or remove notes.txt first.
To read the contents without writing a new file, use bzcat and pipe the output to less
:
bzcat notes.txt.bz2 | lessTo check a downloaded file for corruption, use the --test (-t) option. The command prints nothing when the file is intact:
bzip2 -t notes.txt.bz2Extracting 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:
tar -xf archive.tar.bz2 file1 file2When 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:
tar -xf archive.tar.bz2 dir1 dir2If you attempt to extract a file that does not exist in the archive, an error message similar to the following will be shown:
tar -xf archive.tar.bz2 READMEtar: README: Not found in archive
tar: Exiting with failure status due to previous errorsYou 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:
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:
wget -O - https://www.php.net/distributions/php-8.6.0.tar.bz2 | tar -xjThe -O - option tells wget to write the download to standard output. tar extracts the PHP source into a php-8.6.0 directory in the current directory.
If you do not specify a decompression option, tar will indicate which option you should use:
tar: Archive is compressed. Use -j option
tar: Error is not recoverable: exiting nowList tar.bz2 Contents
To list the content of a tar.bz2 file, invoke the tar command with the --list (-t) option:
tar -tf archive.tar.bz2The output will look something like this:
file1
file2
file3If you add the --verbose (-v) option, tar will print additional information such as file permissions, ownership, size, and timestamp:
tar -tvf archive.tar.bz2-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 file3Extracting and Preserving Permissions
When you extract an archive as a regular user, tar applies your umask
to the permissions stored in the archive. The extracted files can end up with fewer permissions than the originals. To restore the permission bits exactly as stored, use the -p (--preserve-permissions) option:
tar -xpf archive.tar.bz2When you run tar as root, -p is the default. As root, tar also restores the original file owners. A regular user becomes the owner of every extracted file. In both cases, tar restores the original modification times.
Handle Existing Files
When extracting, tar will overwrite existing files by default. To skip files that already exist, use the --skip-old-files option:
tar -xf archive.tar.bz2 --skip-old-filesTo overwrite files only if they are older than the archive contents:
tar -xf archive.tar.bz2 --keep-newer-filesTo treat existing files as errors, use the --keep-old-files (-k) option:
tar -xf archive.tar.bz2 --keep-old-filestar: file1: Cannot open: File exists
tar: Exiting with failure status due to previous errorstar leaves file1 untouched and still extracts the files that are missing on disk. The command exits with a non-zero status.
Troubleshooting
tar (child): lbzip2: Cannot exec: No such file or directory
The bzip2 program is not installed. tar runs an external program to decompress the archive. When it cannot find bzip2, it tries lbzip2 and reports the last program it tried. Ubuntu Server does not install bzip2 by default. On Ubuntu, Debian, and derivatives, install it with:
sudo apt install bzip2On Fedora, RHEL, and derivatives, run:
sudo dnf install bzip2bzip2: (stdin) is not a bzip2 file.
The file has a .tar.bz2 name, but it is not compressed with bzip2. Check what the file contains:
file archive.tar.bz2If file reports an HTML document, the download saved an error page, not the archive. Download the file again and check the URL.
tar: This does not look like a tar archive
The file is compressed with bzip2, but it does not contain a tar archive. A plain .bz2 file produces this error. Decompress it with bunzip2, as shown in Extracting Plain .bz2 Files
.
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. It also decompresses faster than bzip2, but compression with xz is slower. Both use the same tar -xf command to extract.
Do I need to install bzip2 to extract tar.bz2 files?
Yes. tar uses the bzip2 program to decompress the archive. Debian installs it by default. Ubuntu Server does not. If tar fails with lbzip2: Cannot exec, 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, listing archive contents, and decompressing plain .bz2 files.
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 is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page