linux解压缩文件_在Linux中一次解压缩或解压缩许多文件

linux解压缩文件_在Linux中一次解压缩或解压缩许多文件

linux解压缩文件

If you’ve got a directory with dozens of zipped or rar’d files, you can run a single command to unzip them all in one step, thanks to the power of the bash shell.

如果您有一个包含数十个压缩或rar文件的目录,那么由于bash shell的强大功能,您可以运行一个命令将其全部解压缩。

For this task, we’ll use bash’s for loop command structure. Replace <var> with a variable name, and <list> with either a command that outputs a list or an explicit list.

对于此任务,我们将使用bash的for循环命令结构。 将<var>替换为变量名,并将<list>替换为输出列表或显式列表的命令。

for <var> in <list>do   command $<var>;done

对于<list>中的<var>执行命令$ <var>;完成

You can run it on a single line with this syntax instead:

您可以使用以下语法在一行上运行它:

for <var> in <list>;do command $<var>;done

对于<列表>中的<var>;执行命令$ <var>;完成

So if you want to unrar a list of files, you could use this command. You don’t necessarily need the quotes, but it helps when the filenames have spaces or something like that in them.

因此,如果要解压缩文件列表,可以使用此命令。 您不一定需要使用引号,但是当文件名中包含空格或类似内容时,它会有所帮助。

for f in *.rar;do unrar e “$f”;done

对于* .rar中的f;执行unrar e“ $ f”;完成

If you wanted to use 7zip to extract a list of files:

如果要使用7zip提取文件列表:

for f in *.001;do 7z e “$f”;done

对于* .001中的f;执行7z e“ $ f”;完成

Or if you wanted to unzip a list of files:

或者,如果您想解压缩文件列表:

for f in *.zip;do unzip “$f”;done

对于* .zip中的f;解压缩“ $ f”;完成

You could even chain commands together if you wanted to. For instance, if all your zip files contained .txt files and you wanted to unzip them and then move the unzipped files to another directory:

如果愿意,您甚至可以将命令链接在一起。 例如,如果您所有的zip文件都包含.txt文件,并且您想解压缩它们,然后将解压缩的文件移动到另一个目录:

for f in *.zip;do unzip “$f”;done; for f in *.txt;do mv “$f” /myfolder/;done

对于* .zip中的f;解压缩“ $ f”;完成; 对于* .txt中的f;执行mv“ $ f” / myfolder /;完成

The bash shell is just so incredibly powerful… this doesn’t even tap the power, but it should give you a good idea of what is possible.

bash shell的功能是如此强大,甚至无法发挥作用,但它应该使您对可能的情况有了一个很好的了解。

翻译自: https://www.howtogeek.com/howto/ubuntu/unzip-or-unrar-many-files-at-once-in-linux/

linux解压缩文件