Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 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
add comment

Your Answer

 
discard

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.