How to extract files from a bz2 archive in Linux

- by

If you’ve ever tried to decompress a file that ends in tar.bz2 using the tar command with the standard -x option, you’ll have noticed that it doesn’t work. That’s because some versions of tar don’t understand the bzip2 codec used in these archives.

However, you can tell tar to use this option by specifying the -j parameter, like so:

tar -xjf yourfile.tar.bz2

If this still doesn’t work, we can use the dedicated bzip2 command like so:

bzip2 -d yourfile.tar.bz2

The -d switch stands for “decompress”. Notice that this will extract all files and delete the original .bz2 file by default. Very convenient indeed! If you’d like to keep it, just pass the -k switch (for “keep”), like this:

bzip2 -dk yourfile.tar.z2

Checkout man bzip2 for more details, or pass the –help for as quick overview.

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.