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

dgibbs
  • 661
  • 2
  • 11
  • 22

1 Answers1

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
dsmsk80
  • 5,817
  • 18
  • 22