A tar.bz2 file is a compressed archive using the bzip2 algorithm, commonly used in Linux systems for efficient file compression. This format combines the functionality of tar, which groups multiple files into one archive, with bzip2 compression, which reduces file size. The tradeoff is that the compression process requires more CPU resources compared to other formats like tar.gz.
The tar.bz2 format is less commonly used than other compression formats, but it is preferred when a higher compression rate is needed. While this format offers improved storage efficiency, extracting files from tar.bz2 archives requires slightly more processing power. However, it is easily manageable through the tar command-line utility available in most Linux distributions.
This guide explains how to extract a tar.bz2 archive using the tar command in Linux. The tar command efficiently handles both creating and extracting compressed archives, including those using bzip2 compression. Following the steps below, you will be able to quickly extract your files.
Steps to extract tar.bz2 files in Linux:
- Open your preferred terminal application.
You can use any terminal emulator, such as GNOME Terminal or Konsole, depending on your Linux distribution.
- Verify if the file is a valid bzip2 archive (optional).
$ file file.tar.bz2 file.tar.bz2: bzip2 compressed data, block size = 900k
- Create a directory to store the extracted files (optional).
$ mkdir destination
- Change to the directory where you want the extracted files (optional).
cd destination/
- Use the tar command to extract the files from the tar.bz2 archive.
$ tar -xjvf /home/user/archive.tar.gz archive/ archive/subfolder-02/ archive/subfolder-02/filename-02 archive/subfolder-02/filename-01 archive/subfolder-01/ archive/subfolder-01/filename-02 archive/subfolder-01/filename-01
The full version of the command would be tar --extract --bzip2 --verbose --file=/home/user/file.tar.bz2. The xvjf options in the command stand for extract, verbose, bzip2, and file. You need to specify the path to your tar.bz2 file.
- Confirm the extraction by listing the files in the destination directory.
$ ls -R .: archive ./archive: subfolder-01 subfolder-02 ./archive/subfolder-01: filename-01 filename-02 ./archive/subfolder-02: filename-01 filename-02
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.