[英]Decompress .gz files from subfolders (recursively) into root folder
Here is the situation : I have a folder, containing a lot of subfolders, some of them containing .gz compressed files (NOT tar, just compressed text files). 这是一种情况:我有一个文件夹,其中包含许多子文件夹,其中一些包含.gz压缩文件(不是tar,只是压缩的文本文件)。 I want to recursively decompress all these .gz files into the root folder, but I can't figure out the exact way to do it.
我想递归地将所有这些.gz文件解压缩到根文件夹中,但是我不知道确切的方法。
I have my folders like that : /folderX/subfolder1/file.gz 我有这样的文件夹:/folderX/subfolder1/file.gz
by using 通过使用
gzip -c -d -r *.gz
I can probably extract all the files at once, but they will remain in their respective subfolders. 我可能可以一次提取所有文件,但是它们将保留在各自的子文件夹中。 I want them all in /folderX/
我希望它们全部在/ folderX /
find -name *.gz
gives me the correct list of the files I am looking for, but I have no idea how to combine the 2 commands. 给我正确的文件列表,但我不知道如何组合这两个命令。 Should I combine these commands in a script ?
我应该在脚本中组合这些命令吗? Or is there a functionality of gzip that I have missed allowing to decompress everything in the folder from which you are executing the command ?
还是我错过了gzip的功能,可以对您从中执行命令的文件夹中的所有文件进行解压缩?
Thanks for the help ! 谢谢您的帮助 !
You can use a while..done loop that iterate the input: 您可以使用while..done循环来迭代输入:
find dirname -name *.gz|while read i; do gzip -c -d -r $i; done
You can also use xargs, with the additional benefit of dealing with spaces (" ") in the file name of parameter -0: 您还可以使用xargs,其附加好处是可以处理参数-0的文件名中的空格(“”):
find dirname -name '*.gz' -print0 | xargs -0 -L 1 gzip -c -d -r
The "-print0" output all the files found separated by NULL character. “ -print0”输出找到的所有文件,用NULL字符分隔。 The -0 switch of xargs rebuild the list parsing the NULL character and applies the "gzip..." command to each of them.
xargs的-0开关将重建分析NULL字符的列表,并将“ gzip ...”命令应用于每个列表。 Pay attention to the "-L 1" parameter which tells xargs to pass only ONE file at a time to gzip.
注意“ -L 1”参数,该参数告诉xargs一次仅将一个文件传递给gzip。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.