【Linux】一步一步学Linux——zip命令(67)
发布日期:2021-06-29 21:00:00 浏览次数:3 分类:技术文章

本文共 3161 字,大约阅读时间需要 10 分钟。

00. 目录

文章目录

01. 命令概述

zip 命令是一个应用广泛的跨平台的压缩工具,压缩文件的后缀为 .zip文件

zip程序将一个或多个压缩文件与有关文件的信息(名称、路径、日期、上次修改的时间、保护和检查信息以验证文件完整性)一起放入一个压缩存档中。可以使用一个命令将整个目录结构打包到zip存档中。

对于文本文件来说,压缩比为2:1和3:1是常见的。zip只有一种压缩方法(通缩),并且可以在不压缩的情况下存储文件。(如果添加了bzip 2支持,zip也可以使用bzip 2压缩,但这些条目需要一个合理的现代解压缩来解压缩。当选择bzip 2压缩时,它将通货紧缩替换为默认方法。)zip会自动为每个要压缩的文件选择更好的两个文件(通缩或存储,如果选择bzip2,则选择bzip2或Store)。

02. 命令格式

zip [参数] [文件]

03. 常用选项

-A:调整可执行的自动解压缩文件;-b
<工作目录>
:指定暂时存放文件的目录;-c:替每个被压缩的文件加上注释;-d:从压缩文件内删除指定的文件;-D:压缩文件内不建立目录名称;-f:此参数的效果和指定“-u”参数类似,但不仅更新既有文件,如果某些文件原本不存在于压缩文件内,使用本参数会一并将其加入压缩文件中;-F:尝试修复已损坏的压缩文件;-g:将文件压缩后附加在已有的压缩文件之后,而非另行建立新的压缩文件;-h:在线帮助;-i
<范本样式>
:只压缩符合条件的文件;-j:只保存文件名称及其内容,而不存放任何目录名称;-J:删除压缩文件前面不必要的数据;-k:使用MS-DOS兼容格式的文件名称;-l:压缩文件时,把LF字符置换成LF+CR字符;-ll:压缩文件时,把LF+cp字符置换成LF字符;-L:显示版权信息;-m:将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中;-n
<字尾字符串>
:不压缩具有特定字尾字符串的文件;-o:以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同;-q:不显示指令执行过程;-r:递归处理,将指定目录下的所有文件和子目录一并处理;-S:包含系统和隐藏文件;-t
<日期时间>
:把压缩文件的日期设成指定的日期;-T:检查备份文件内的每个文件是否正确无误;-u:更换较新的文件到压缩文件内;-v:显示指令执行过程或显示版本信息;-V:保存VMS操作系统的文件属性;-w:在文件名称里假如版本编号,本参数仅在VMS操作系统下有效;-x
<范本样式>
:压缩时排除符合条件的文件;-X:不保存额外的文件属性;-y:直接保存符号连接,而非该链接所指向的文件,本参数仅在UNIX之类的系统下有效;-z:替压缩文件加上注释;-$:保存第一个被压缩文件所在磁盘的卷册名称;-
<压缩效率>
:压缩效率是一个介于1~9的数值。

04. 参考示例

4.1 压缩文件

[deng@localhost test]$ zip passwd.zip passwd   adding: passwd (deflated 61%)[deng@localhost test]$ lsetc  passwd  passwd.zip  test[deng@localhost test]$

4.2 指定压缩率为8

[deng@localhost test]$ zip passwd1.zip -8 passwd  adding: passwd (deflated 61%)[deng@localhost test]$

4.3 压缩目录

选项 -r 表示递归压缩子目录下所有文件,将目录 test压缩为 test.zip

[deng@localhost test]$ zip -r test.zip test  adding: test/ (stored 0%)  adding: test/a (stored 0%)  adding: test/b (stored 0%)  adding: test/c (stored 0%)  adding: test/d (stored 0%)  adding: test/e (stored 0%)[deng@localhost test]$ lsetc  passwd  passwd1.zip  passwd.zip  test  test.zip[deng@localhost test]$

4.4 压缩目录和文件

将目录test和文件paswd 压缩成为 test1.zip

[deng@localhost test]$ zip -r test1.zip test passwd  adding: test/ (stored 0%)  adding: test/a (stored 0%)  adding: test/b (stored 0%)  adding: test/c (stored 0%)  adding: test/d (stored 0%)  adding: test/e (stored 0%)  adding: passwd (deflated 61%)[deng@localhost test]$

4.5 从压缩文件内删除指定文件

[deng@localhost test]$ zip -d test1.zip passwddeleting: passwd[deng@localhost test]$

4.6 向压缩文件中添加指定文件

[deng@localhost test]$ zip -m test1.zip  passwd  adding: passwd (deflated 61%)[deng@localhost test]$

4.7 压缩文件时排除某个文件

[deng@localhost test]$ zip -r test2.zip test -x test/a  adding: test/ (stored 0%)  adding: test/b (stored 0%)  adding: test/c (stored 0%)  adding: test/d (stored 0%)  adding: test/e (stored 0%)[deng@localhost test]$

4.8 压缩多个文件

[deng@localhost test]$ zip -v t.zip a b c d e  adding: a     (in=0) (out=0) (stored 0%)  adding: b     (in=0) (out=0) (stored 0%)  adding: c     (in=0) (out=0) (stored 0%)  adding: d     (in=0) (out=0) (stored 0%)  adding: e     (in=0) (out=0) (stored 0%)total bytes=0, compressed=0 -> 0% savings[deng@localhost test]$ lsa  b  c  d  e  t.zip[deng@localhost test]$

4.9 不显示指令执行过程

[deng@localhost test]$ zip -q a.zip a[deng@localhost test]$ zip b.zip a  adding: a (stored 0%)[deng@localhost test]$

05. 附录

参考:

转载地址:https://dengjin.blog.csdn.net/article/details/97242708 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:【Linux】一步一步学Linux——unzip命令(68)
下一篇:【Linux】一步一步学Linux——bunzip2命令(66)

发表评论

最新留言

不错!
[***.144.177.141]2024年04月12日 12时01分04秒