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!
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.
-
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.– SimonSep 4, 2013 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.– SimonSep 14, 2013 at 10:11