我想将所有内容(包括当前目录中的文件和文件夹)压缩并打包到 Ubuntu 上的单个 ZIP 文件中。
最方便的命令是什么(以及需要安装的工具的名称(如果有))?
编辑:如果我需要排除一个文件夹或多个文件怎么办?
答案1
安装zip
与使用
zip -r foo.zip .
您可以使用标志-0
(无)到-9
(最佳)来更改压缩率
可以通过-x
标志来排除文件。从手册页:
-x files
--exclude files
Explicitly exclude the specified files, as in:
zip -r foo foo -x \*.o
which will include the contents of foo in foo.zip while excluding all the files that end in .o. The backslash avoids the shell filename substitution, so that the name matching
is performed by zip at all directory levels.
Also possible:
zip -r foo foo [email protected]
which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst.
The long option forms of the above are
zip -r foo foo --exclude \*.o
and
zip -r foo foo --exclude @exclude.lst
Multiple patterns can be specified, as in:
zip -r foo foo -x \*.o \*.c
If there is no space between -x and the pattern, just one value is assumed (no list):
zip -r foo foo -x\*.o
See -i for more on include and exclude.