3

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

5

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
  • Never would of guessed that. Works perfectly. Thank you :) – dgibbs Aug 16 '13 at 11:21

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.