Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

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:

DIR=/any/dir/where/you/want/extract/files
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.

share|improve this answer
    
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
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.