Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a file foo.tbz2 in a directory. I want to extract the tar file from the archive, but to a different directory. It seems like bunzip2 will only extract the archive to the same directory as the archive. Am I missing something?

This works, but I'm wondering if there is a better way:

cd /another/directory
bunzip2 -k -c /original/directory/foo.tbz2
share|improve this question
I think the cd and extract method is the intended method. What is wrong with it? – jw013 Aug 15 '12 at 21:14
@jw013 There is nothing wrong with it, just curious about possible alternatives. – longneck Aug 16 '12 at 14:35
up vote 3 down vote accepted

You can use the other bzip2 tools:

bzcat foo.tbz2 > /another/directory/foo.tar

bzip2 -ckd foo.tbz2 > /another/directory/foo.tar

Note that if you want to untar it to another directory, you could use the -C option to tar:

tar xjf foo.tbz2 -C /another/directory
share|improve this answer
+1 for spreading the word on tar's -C flag. It's really handy, but hardly anyone knows it. – djf Aug 15 '12 at 21:59
I specifically do not want to extract the tar archive, but bzcat looks exactly like what I was looking for. Thanks! – longneck Aug 15 '12 at 22:54

I have suggestion: If you have a *bz2 file whether *.tar.bz2 or *.bz2 don't use bunzip just use tar command, Because tar command has many feature that can help you.

tar -jxf *.tar.bz2 -C yourplace/
tar -jf *.bz2 -C yourplace/
share|improve this answer
I don't want the tar file extracted. The end result of whatever command I use needs to be the tar file in a different directory than the bz2 file, and the original bz2 file must not be deleted or modified. – longneck Aug 16 '12 at 14:34
the above commands don't modify original files, note: tar file work each algorithm such as *gz *tar *lm *7 and so on. – PersianGulf Aug 16 '12 at 14:38

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.