递归压缩文件夹,保存给定的子文件夹(Linux)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11207348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Zip folder recursively, save for a given sub folder (Linux)
提问by Hermann Ingjaldsson
In Linux zip, is it possible to zip a folder recursively except for a given sub-path?
在 Linux zip 中,除了给定的子路径外,是否可以递归压缩文件夹?
For instance, to zip 'base_folder' and all its sub folders except 'base_folder/sub_folder'.
例如,压缩“base_folder”及其除“base_folder/sub_folder”之外的所有子文件夹。
Is it possible? And if so, how?
是否可以?如果是这样,如何?
采纳答案by minopret
zip -r base_folder.zip base_folder -x base_folder/sub_folder/\* base_folder/another_sub_folder/\*
zip -r base_folder.zip base_folder -x base_folder/sub_folder/\* base_folder/another_sub_folder/\*
(I have incorporated the improved information from your experience that you have kindly offered in your comment.)
(我已将您在评论中善意提供的经验中的改进信息纳入其中。)
For more information: man zip
想要查询更多的信息: man zip
回答by marius_5
find the files, exclude the folder, xargs the remaining files to tar or zip or whatever:
找到文件,排除文件夹,将剩余的文件 xargs 到 tar 或 zip 或其他任何内容:
find /in/your/dir | grep -v 'name_of_dir_to_be_excluded' | xargs tar jcvf nameOfArchive.tar.bz2
回答by Andy Lester
You can use tar
with --exclude
, and use the -z
option to gzip the output tar file.
您可以使用tar
with --exclude
,并使用-z
gzip 输出 tar 文件的选项。