Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ubuntu extract multiple .tar.gz files to new directory [closed]

Tags:

linux

ubuntu

I have about 200,000 thumbs in a folder that are all gzipped ending with .tar.gz What I am looking to do is extract all the files in that folder but to a different folder. Does anyone know a command to do this? I found this online but I wouldnt know how to use it to extract to a different folder.

for i in *.tar.gz; do tar -xvzf $i; done
like image 772
chris Avatar asked Mar 03 '11 07:03

chris


People also ask

How do I extract only certain files from a tar?

Now, if you want a single file or folder from the “tar” file, you need to use the name of the “tar” file and the path to a single file in it. So, we have used the “tar” command with the “-xvf” option, the name of the “tar” file, and the path of a file to be extracted from it as below.

How unzip multiple gz file in Linux?

how can I extract multiple gzip files in directory and subdirectories? It will extract all files with their original names and store them in the current user home directory( /home/username ). gunzip *. gz // This command also will work.


2 Answers

Add the -C option to select the target directory:

for i in *.tar.gz; do tar xvzf $i -C path/to/output/directory; done
like image 65
Delan Azabani Avatar answered Sep 18 '22 07:09

Delan Azabani


Right now you are using

tar

to extract all the files. I believe that you can set which directory to output to.

It would be something like this:

for i in *.tar.gz; do tar -xvzf $i -C directory; done

where directory is the path of the folder you want to extract the files to.

Refer to http://www.computerhope.com/unix/utar.htm (documentation on tar).

like image 28
quarkdown27 Avatar answered Sep 21 '22 07:09

quarkdown27