HiBlog Linux and Windows Server

How to Extract a .tar.bz2 Archive on Linux

  • Ali GhanimatiAuthor
  • Last updated
  • 2 minutesReading time
  • 1,238Views
  • Ali Ghanimati
  • Last updated:
  • 2 min read
  • 1,238 views
How to Extract a .tar.bz2 Archive on Linux

A .tar.bz2 file is a tar archive compressed with bzip2. GNU tar can list and extract it directly, so you do not need to create an uncompressed intermediate file. Listing the contents first helps you learn the paths and avoid overwriting an existing directory.

Use a separate destination with enough space. Uncompressed files may take much more space than the archive. When handling an archive from someone else, inspect file names and paths and avoid extracting it as an administrator.

List the archive

tar -tjf archive.tar.bz2

Here -t lists entries, -j selects bzip2, and -f identifies the archive. Use the exact paths in this output if you plan to extract individual files.

Extract all files

mkdir extracted && tar -xjf archive.tar.bz2 -C extracted

The example uses a new directory and extracts only if its creation succeeds. -x requests extraction, and -C changes the destination directory.

Extract a single entry

For a new or existing intended destination called extracted, use the exact member path you saw in the listing:

tar -xjf archive.tar.bz2 -C extracted -- docs/guide.txt

Check the output and open the extracted file. If tar reports a missing member, look for differences such as a leading ./ or a top-level directory. GNU tar manual for Ubuntu.

Share Post

hidata.org/en/blog/how-to-unzip-tar-bz2-files-in-linux/
In Social Media

Add Comment

Related Articles