ubuntu提取多个. tar。gz文件到新目录。

时间:2021-07-12 21:10:54

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.

我在一个文件夹里有20万个拇指,它们都以。tar结尾。gz我要做的是将那个文件夹中的所有文件解压缩到另一个文件夹中。有人知道这样做的命令吗?我在网上找到了这个,但我不知道如何使用它来提取到一个不同的文件夹。

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

4 个解决方案

#1


27  

Add the -C option to select the target directory:

添加-C选项,选择目标目录:

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

#2


4  

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

请参考http://www.computerhope.com/unix/utar.htm(关于tar的文档)。

#3


2  

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

HTH

HTH

#4


2  

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

c选项可能更好。你也可以做的事:

$ 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

$ mkdir /path/to/newfolder $用于*.tar.gz中的i;do files="$files $(readlink -f $i)";完成#在$files中为i构建文件名$ cd /path/to/newfolder $的绝对列表;焦油-zxvf $ i;完成

#1


27  

Add the -C option to select the target directory:

添加-C选项,选择目标目录:

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

#2


4  

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

请参考http://www.computerhope.com/unix/utar.htm(关于tar的文档)。

#3


2  

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

HTH

HTH

#4


2  

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

c选项可能更好。你也可以做的事:

$ 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

$ mkdir /path/to/newfolder $用于*.tar.gz中的i;do files="$files $(readlink -f $i)";完成#在$files中为i构建文件名$ cd /path/to/newfolder $的绝对列表;焦油-zxvf $ i;完成