bash 如何在没有顶级文件夹的情况下压缩文件但保留子文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13719408/
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
How to zip files without the top level folder but keep the sub folders
提问by zdd
Suppose I have a folder named abc, it has several sub folders recursively, I want to zip everything under abc, when I use the following command
假设我有一个名为 abc 的文件夹,它递归地有几个子文件夹,我想在 abc 下压缩所有内容,当我使用以下命令时
zip -r abc.zip abc/*
I get abc.zip, but it contains the top level folder abc, and everything is under abc, like abc/xxx, abc/yyy etc, How can I remove the top level folder abc? I want to put everything directly in abc.zip.
我得到了 abc.zip,但它包含顶级文件夹 abc,所有内容都在 abc 下,如 abc/xxx、abc/yyy 等,如何删除顶级文件夹 abc?我想把所有东西直接放在 abc.zip 中。
Note:
笔记:
- I can only zip from outside of the folder, so navigate to folder abc, and zip * is not work for me
- I need to run this command in a single line, I can separated multiple commands by ;
- option -j also does not work, since it remove the sub folders, I want to keep them there.
- 我只能从文件夹外部进行压缩,因此导航到文件夹 abc,而 zip * 对我不起作用
- 我需要在一行中运行这个命令,我可以用 ; 分隔多个命令;
- 选项 -j 也不起作用,因为它删除了子文件夹,我想将它们保留在那里。
回答by Gilbert
cd abc zip -r ../abc.zip *
Though I will say in most cases keeping it abc makes for easier management.
虽然我会说在大多数情况下保持它 abc 可以更容易地管理。

