Howto inflate AND extract a .tar.bz2 using the 7-zip command line tool

7ztar

I have a .tar.bz2 file that I want to be decompressed and extracted via the 7-zip commandline tool.

So basically I'm looking for the equivalent of

tar -xjf foo.tar.bz2

with 7-zip there is only the option "x" for extract, so doing

7z x foo.tar.bz2

gives me the inflated foo.tar file instead of unpacking all the directories inside the tar.
What's the corresponding option for 7z?

Best Answer

With 7zip, you have to run the command twice, once to decompress and again to extract. The tar file format is just a "wad" of everything stuck end to end. Then the whole tar file is compressed using various compression algorithms, in your example bzip. Basically the resulting file has two layers. When you "extract" the bzip layer you get a tar file, then when you extract the tar file you get a bunch of individual files.

7zip doesn't handle multiple layers at once, although it is able to handle both layers:

7z x foo.tar.bz2
7z x foo.tar

Actually the standard unix tools work the same way:

bunzip2 foo.tar.bz2
tar xf foo.tar

However the the unix tar command has convenience features that call the secondary compression and decompression steps using another program before/after it handles the tar part. Basically the -j argument calls bzip2/bunzip2, you just don't see the second step. Likewise -z will call gzip/gunzip, etc.