7

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?

2

4 Answers 4

4

While you can't do this in one command, you can make use of a shell pipeline to chain two 7z commands into one command line like so:

7z e -so .\Downloads\enron_mongo.tar.bz2 | 7z e -si -ttar
3

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.

2

How about a shorter version of the 7z and tar combination using standard out and pipes?

# 7z x -so my-compressed-tarball.tar.bz2| tar xf -
1
7z x -so foo.tar.bz2 | 7z x -si -ttar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.