Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I think this may be a simple question but cannot find the answer.

I am trying to extract some files from a tar file. These files are in a directory within the tar file. I tried the following however this didnt work

tar -zxvf filename.tar.gz folder/*

I thought this would simply extract all the files in the directory but not the directory itself. The only way I think I could do it currently would be something like this.

tar -zxvf filename.tar.gz folder
mv folder/* ../
rm folder

Hopefully there is a more efficient method to complete this task. Thank you

share|improve this question
up vote 5 down vote accepted

With GNU tar, you can use --strip-components option which strips a specified number of leading components from file names before extraction:

tar zxfv filename.tar.gz --strip-components=1
tar zxfv filename.tar.gz folder/ --strip-components=1
share|improve this answer
Never would of guessed that. Works perfectly. Thank you :) – dgibbs Aug 16 '13 at 11:21

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.