Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i need to decompress .bz2 files inside a .tar archive (two step decompression)

For example:


has multiple .bz2 files inside.

How can I extract them with a single command in linux. I have tried this but it does n't work.

tar -xvf requested_files_1.tar | bzip2 -d

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Your pipe doesn't work because tar isn't extracting the files to stdout, it's just listing them. bzip2 therefore tries to decompress the list of filenames as plain text, which of course, is not a compressed file's contents (i.e., it's using the plain text as the contents of the file to be extracted).

In order to use the output from tar xvf as a list of filenames for bzip2 to extract, you can do the following:

bzip2 -d $(tar xvf requested_files_1.tar)

The v option for tar here is required to list the extracted files for bzip2.

share|improve this answer
This is the perfect and most efficient piece of code. It worked flawlessly. it was even better when I put a for loop inside the parenthesis and made it to run for all the tar files in that directory. thanks again. >bzip2 -d $(for i in *.tar;do tar xvf $i;done) – Foad Yousef Apr 16 '14 at 19:02

Sounds like a duplicate of

So your script would be something like this:


for f in `ls *.tar` ; do
    mkdir "$dir"
    cd $dir
    tar -xf "../$f"
    bunzip2 *.bz2
    cd ..
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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