What is the command to extract a .tar.bz2 file?
tar -xjf release-2.4.tar.bz2
-x extracts, -j tells tar to run bzip2, and -f names the archive. GNU tar on Ubuntu, Debian and the Enterprise Linux images, and bsdtar on FreeBSD, also detect compression by themselves, so tar -xf release-2.4.tar.bz2 works just as well. The .tbz2 and .tbz extensions are the same format with a shorter name.
If tar complains that bzip2 is missing, install it: apt install bzip2 or dnf install bzip2. Minimal images sometimes leave it out.
How do I check what is inside first?
List before you extract, especially with archives from someone else. Some unpack hundreds of files straight into the current folder instead of one neat subfolder:
tar -tjf release-2.4.tar.bz2 | head -20 tar -tjf release-2.4.tar.bz2 | cut -d/ -f1 | sort -u
The second line shows the top-level names. One name means a tidy archive; many names means you should extract into a fresh folder. For a detailed listing with sizes and owners, add -v.
How do I extract into a specific folder?
install -d /opt/release-2.4 tar -xjf release-2.4.tar.bz2 -C /opt/release-2.4 --strip-components=1
-C switches to the target folder before extracting; it must already exist. --strip-components=1 drops the archive's top folder, so release-2.4/bin/tool lands at /opt/release-2.4/bin/tool instead of one level deeper.
Can I pull out a single file?
Yes. Name the path exactly as the listing shows it:
tar -xjf release-2.4.tar.bz2 release-2.4/conf/defaults.ini tar -xjf logs-2026-11.tar.bz2 --wildcards '*/nginx/error.log*'
bzip2 is a stream format, so tar still has to decompress the archive up to the file you want, even for one small file. On very large archives that is the slow part, which leads to the next question.
How do I make big archives extract faster?
Use a parallel bzip2 tool. Classic bzip2 uses one core. lbzip2 and pbzip2 spread the work across all of them, and decompression with lbzip2 scales well even on archives created by plain bzip2:
apt install lbzip2 # dnf install lbzip2 via EPEL on Enterprise Linux tar -I lbzip2 -xf dataset-2026.tar.bz2 -C /srv/data
On a machine like D3 with 56 cores, the difference on a multi-gigabyte archive is dramatic. Even the six cores of an S1 make a clear dent.
| Tool | Cores used | Notes |
|---|---|---|
bzip2 | 1 | Always available |
pbzip2 | All | Fastest on archives it created itself |
lbzip2 | All | Parallel on any bzip2 file |
What about a plain .bz2 file without tar?
A file like access.log.bz2 is a single compressed file, not an archive. Decompress it directly:
bunzip2 -k access.log.bz2 # -k keeps the original bzcat access.log.bz2 | grep ' 500 ' | wc -l
bzcat, bzgrep and bzless read compressed logs without writing an uncompressed copy, which saves disk space on busy log folders.
What errors might I see?
- "bzip2: (stdin) is not a bzip2 file": the file is something else.
file archive.tar.bz2tells you what; it may be gzip or xz with the wrong name, or an HTML error page saved by a failed download. - "Unexpected EOF in archive": the download was cut short. Fetch it again and compare its checksum with
sha256sum. - "Cannot open: Permission denied": the target folder is not writable by your user. Extract somewhere you own, or use sudo with care.
Should I create new archives with bzip2?
Usually not anymore. bzip2 compresses well but slowly. For new archives, gzip is faster and universal, while zstd and xz compress better and decompress faster than bzip2. The trade-offs are covered in Create tar.gz archives. Keep bzip2 for opening older archives, which you will meet for years to come.
When a partner or an old build script insists on the format, it is one flag: tar -cjf export-2026-12.tar.bz2 -C /srv exports, or tar -I lbzip2 -cf to compress on every core. The file opens on any system made in the last twenty years, which is the format's lasting strength.
Keep Reading
Create tar.gz archives
Pack folders into tar.gz archives, choose compression levels, use pigz on many cores and compare gzip with zstd and xz.
OpenExtract .tar.gz files
Unpack tar.gz and .tgz archives from the command line: target folders, single files, stripped paths, ownership and safe handling of unknown archives.
OpenThe tar command
A working reference for tar: modes, compression flags, appending, comparing, incremental backups and the options people forget.
OpenFAQ
Quick Answers
Run tar -xjf followed by the file name. Modern tar also detects the compression with tar -xf.
Add -C with an existing target folder, for example tar -xjf file.tar.bz2 -C /opt/app.
Yes. Install lbzip2 and run tar -I lbzip2 -xf to use every core.
A .bz2 file is one compressed file; .tar.bz2 is a tar archive of many files compressed with bzip2.
Something else is inside: another compressor, or a failed download saved under that name. Running file on it reveals which.