Tag Archives: tar

How to extract files from a bz2 archive in Linux

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:

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

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:

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