开发者

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

开发者 https://www.devze.com 2023-02-14 07:46 出处:网络
Closed. This question is off-topic. It is not currently开发者_运维百科 accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently开发者_运维百科 accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 9 years ago.

Improve this question

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


Add the -C option to select the target directory:

for i in *.tar.gz; do tar xvzf $i -C path/to/output/directory; done


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).


actdir=`pwd`
for files in *tar.gz ; do
  filedir=`basename $files .tar.gz`
  mkdir $filedir 
  cd $filedir
  tar -xzf ../$files
  cd $actdir
done

HTH


The -C option is probably better. You could also do:

$ mkdir /path/to/newfolder
$ for i in *.tar.gz; do files="$files $(readlink -f $i)"; done # builds absolute list of filenames
$ cd /path/to/newfolder
$ for i in $files; do tar -zxvf $i; done

0

精彩评论

暂无评论...
验证码 换一张
取 消