Ter*_* Li 131 packaging ubuntu zip compression
我想在 Ubuntu 上将所有内容(包括当前目录中的文件和文件夹)压缩并打包到一个 ZIP 文件中。
对此最方便的命令是什么(以及需要安装的工具的名称,如果有的话)?
编辑:如果我需要排除一个文件夹或多个文件怎么办?
Ska*_*Rat 175
安装zip和使用
zip -r foo.zip .
Run Code Online (Sandbox Code Playgroud)
您可以使用标志-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 -x@exclude.lst
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.
Run Code Online (Sandbox Code Playgroud)
Mar*_*oma 26
我想很多通过谷歌来回答这个问题的人在写“zip”时的意思是“归档和压缩”。zip 格式的替代方法是tar:
tar -czf copy.tar.gz whatever/
Run Code Online (Sandbox Code Playgroud)
压缩存档文件将是 copy.tar.gz 并且内容将是文件夹中的所有内容。
-c, --create
create a new archive
-z, --gzip, --gunzip --ungzip
-f, --file ARCHIVE
use archive file or device ARCHIVE
Run Code Online (Sandbox Code Playgroud)