如何在目标目录中递归地压缩所有文件?

我想知道用什么命令来递归地压缩目标目录中的所有文件? 我试图使用unzip命令,但它没有用。

我试过解压缩目标文件夹中的所有zip文件的命令?

使用以下命令。 将替换为ZIP文件的路径,将替换为目标文件夹:

  • 对于GZ文件

     find  -type f -name "*.gz" -exec tar xf {} -C  \; 

    要么

     find  -type f -name "*.gz" -print0 | xargs -0 -I{} tar xf {} -C  
  • 对于ZIP文件

     find  -type f -name "*.zip" -exec unzip {} -d  \; 

    要么

     find  -type f -name "*.zip" -print0 | xargs -0 -I{} unzip {} -d  

gunzip-r选项。 来自man gunzip

  -r --recursive Travel the directory structure recursively. If any of the file names specified on the command line are directories, gzip will descend into the directory and compress all the files it finds there (or decompress them in the case of gunzip ). 

所以,如果你想在目录/foo/bar及其所有子目录中压缩所有压缩文件( gunzip当前可以解压缩由gzip,zip,compress,compress -H或pack创建的文件):

 gunzip -r /foo/bar 

这也将处理带空格的文件名。