简体   繁体   English

将.gz文件从子文件夹解压缩(递归)到根文件夹中

[英]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.

相关问题 如何以文件夹及其子文件夹的形式递归复制文件作为符号链接 - How to recursively copy files under a folder and its subfolders as symbolic links gz文件解压缩过程的不同行为 - Different behaviours for gz files decompress process 如何递归地将文件夹及其所有子文件夹和文件设置为 drwxrwxrwx - How do I recursively set a folder and all of its subfolders and files to drwxrwxrwx 如何创建 tar 文件,以便将文件放在 tar.gz 文件的根文件夹中 - how to create tar file so that files at placed at root folder of tar.gz file 根据带有 Linux 的前缀号将文件从文件夹移动到子文件夹 - moving files from a folder into subfolders based on the prefix number with Linux 递归更改文件夹和子文件夹中的文件名而不更改文件路径 - Recursively change file name in folder and subfolders without changing file path Linux-递归列出文件夹中所有文件的性能 - Linux - Recursively list all files from folder with performance 如何在Linux控制台中递归地将文件从文件夹发送到命令? - How to send files from folder recursively to command in linux console? (Linux) 用另一个文件中的数据递归地覆盖文件夹中的所有文件 - (Linux) Recursively overwrite all files in folder with data from another file 如何使用 Bash 中的 iconv 递归重命名文件和文件夹 - How to recursively rename files and folder with iconv from Bash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM