I m trying to extract files contained within a directory in a tar.gz file. The extract I m using is tar zxvf foo.tar.gz. It extracts the files from the archive but removes them from the directory they are in. I want to extracted them to the directory that contains them, and want to be able to do this for multiple archives. Any help would be great!

  • Give it a look here.... ops a little late maybe. – Hastur Jul 5 '16 at 15:28

I'm not soure about your descption. At first list files and be soure where they are:

tar tvzf foo.tar.gz

In your question a hope, files are flat in archive without any directory. If you want extract to any dir, make this and simple extract:

mkdir -p $DIR
tar xvzf foo.tar.gz -C $DIR

I hope this helps. -C option cause, tar themselves move current directory to $DIR and under this do job.

  • I am trying to extract the files in the folders they are contained in. I.e. In the archive there is a folder called LE71460402003130ASN00. This folder contains a series of images. I want to extract that directory with the images in it. – Simon Sep 4 '13 at 22:56
  • Or if there is not a directory called LE71460402003130ASN00 I want to create one. For each tar.gz file, with the name of the archive. – Simon Sep 14 '13 at 10:11

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.