0

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!

2
  • Give it a look here.... ops a little late maybe.
    – Hastur
    Jul 5, 2016 at 15:28
  • Could you give an example tar file and the output you expect?
    – bleistift2
    Dec 28, 2019 at 9:09

1 Answer 1

0

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.

2
  • 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, 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.
    – Simon
    Sep 14, 2013 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .