Linux命令 - zip命令

  Linux中 zip 命令是个使用广泛的压缩程序,文件经它压缩后会另外产生具有".zip"扩展名的压缩文件。

1.语法:

zip [参数] [文件或目录]

2.功能:

  可以压缩文件且保留源文件。

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

例一:将test目录下所有文件和文件夹打包为当前目录下的 test.zip

命令:zip -q -r test.zip /usr/games/test

  生成的压缩文件是在当前打包的目录下。

[root@localhost ~]# ll
总用量 11
drwxr-xr-x. 2 root root    6 5月  12 14:29 公共
drwxr-xr-x. 2 root root    6 5月  12 14:29 模板
drwxr-xr-x. 2 root root    6 5月  12 14:29 视频
drwxr-xr-x. 2 root root    6 5月  12 14:29 图片
drwxr-xr-x. 2 root root    6 5月  12 14:29 文档
drwxr-xr-x. 2 root root    6 5月  12 14:29 下载
drwxr-xr-x. 2 root root    6 5月  12 14:29 音乐
drwxr-xr-x. 2 root root    6 5月  12 14:29 桌面
-rw-------. 1 root root 1247 5月  12 14:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1526 5月  12 14:29 initial-setup-ks.cfg
[root@localhost ~]# zip -q -r test.zip /usr/games/test
[root@localhost ~]# ll
总用量 12
drwxr-xr-x. 2 root root    6 5月  12 14:29 公共
drwxr-xr-x. 2 root root    6 5月  12 14:29 模板
drwxr-xr-x. 2 root root    6 5月  12 14:29 视频
drwxr-xr-x. 2 root root    6 5月  12 14:29 图片
drwxr-xr-x. 2 root root    6 5月  12 14:29 文档
drwxr-xr-x. 2 root root    6 5月  12 14:29 下载
drwxr-xr-x. 2 root root    6 5月  12 14:29 音乐
drwxr-xr-x. 2 root root    6 5月  12 14:29 桌面
-rw-------. 1 root root 1247 5月  12 14:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1526 5月  12 14:29 initial-setup-ks.cfg
-rw-r--r--. 1 root root 1670 5月  25 16:25 test.zip

zip -q -r test.zip *

[root@localhost test]# ll
总用量 24
-rw-r--r--. 1 root root  96 5月  25 15:10 color.sh
-rwxr--r--. 1 root root  96 5月  18 10:15 lncolor
---xr--r--. 1 root root  13 5月  25 10:58 log1.txt
-rwxrw-r-x. 1 root root 592 5月  14 17:00 log2.txt
-rwxr-x--x. 1 root root 655 5月  14 17:06 log3.txt
-rwxr--r--. 1 root root  52 5月  25 10:58 log.txt
[root@localhost test]# zip -q -r test.zip *
[root@localhost test]# ll
总用量 28
-rw-r--r--. 1 root root   96 5月  25 15:10 color.sh
-rwxr--r--. 1 root root   96 5月  18 10:15 lncolor
---xr--r--. 1 root root   13 5月  25 10:58 log1.txt
-rwxrw-r-x. 1 root root  592 5月  14 17:00 log2.txt
-rwxr-x--x. 1 root root  655 5月  14 17:06 log3.txt
-rwxr--r--. 1 root root   52 5月  25 10:58 log.txt
-rw-r--r--. 1 root root 1332 5月  25 16:29 test.zip

例二:从压缩文件 test.zip 中删除文件log.txt

命令:zip -dv test.zip log.txt

[root@localhost test]# zip -dv test.zip log.txt
1>1: updating: log.txt (deflated 29%)

例三:把/games目录下面的test目录压缩为test1.zip

命令: zip -r test1.zip test

[root@localhost games]# zip -r test1.zip testadding: test/ (stored 0%)adding: test/color.sh (deflated 47%)adding: test/lncolor (deflated 47%)adding: test/log1.txt (stored 0%)adding: test/log2.txt (deflated 73%)adding: test/log3.txt (deflated 79%)adding: test/log.txt (deflated 29%)adding: test/test.zip (stored 0%)
[root@localhost games]# ll
总用量 8
-rw-r--r--. 1 root root   96 5月  25 15:16 color.sh
drwxr-xr-x. 2 root root  116 5月  25 16:33 test
-rw-r--r--. 1 root root 3016 5月  25 16:36 test1.zip

例四:把/games目录下面的test文件夹和color.sh压缩成为test2.zip

命令: zip -r test2.zip test color.sh

[root@localhost games]# zip -r test2.zip test color.sh adding: test/ (stored 0%)adding: test/color.sh (deflated 47%)adding: test/lncolor (deflated 47%)adding: test/log1.txt (stored 0%)adding: test/log2.txt (deflated 73%)adding: test/log3.txt (deflated 79%)adding: test/log.txt (deflated 29%)adding: test/test.zip (stored 0%)adding: color.sh (deflated 47%)
[root@localhost games]# ll
总用量 12
-rw-r--r--. 1 root root   96 5月  25 15:16 color.sh
drwxr-xr-x. 2 root root  116 5月  25 16:33 test
-rw-r--r--. 1 root root 3016 5月  25 16:36 test1.zip
-rw-r--r--. 1 root root 3211 5月  25 16:40 test2.zip

例五:将test目录打包成 test3.zip

命令: zip -r test3.zip ./test

  压缩的是包括test目录及以下的文件和文件夹。

[root@localhost games]# zip -r test3.zip ./testadding: test/ (stored 0%)adding: test/color.sh (deflated 47%)adding: test/lncolor (deflated 47%)adding: test/log1.txt (stored 0%)adding: test/log2.txt (deflated 73%)adding: test/log3.txt (deflated 79%)adding: test/log.txt (deflated 29%)adding: test/test.zip (stored 0%)
[root@localhost games]# ll
总用量 16
-rw-r--r--. 1 root root   96 5月  25 15:16 color.sh
drwxr-xr-x. 2 root root  116 5月  25 16:33 test
-rw-r--r--. 1 root root 3016 5月  25 16:36 test1.zip
-rw-r--r--. 1 root root 3211 5月  25 16:40 test2.zip
-rw-r--r--. 1 root root 3016 5月  25 16:42 test3.zip

Linux命令 - zip命令相关推荐

  1. linux命令zip打包,linux下zip命令打包与解包

    linux zip命令的基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] linux zip命令参数列表: -a 将文件转成ASCII模式 -F 尝试修复损坏的压缩文件 -h 显 ...

  2. Nodejs做后端,实现文件压缩下载的几种方案(archiver、compressing、linux的zip命令):

    一. Archiver 1. 安装 npm install archiver 2. 使用 由于需要做文件操作,所以我们需要将fs库也引进来 先创建一个可写流,用于传入压缩包数据 再创建一个archiv ...

  3. Linux 使用zip命令报错:-bash: zip: command not found

    今天学习Linux的时候,使用zip发现报错了,找不到这个命令行 出现这个原因是因为我们没有安装zip/unzip命令,我们使用yum命令进行安装就可以了 yum install zip 希望能帮助到 ...

  4. 解决: bash: unzip: command not found、linux 安装 zip 命令

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 执行解压命令报错: bash: unzip: command not found 2. 安装 ...

  5. Linux的zip命令参数详解

    [用法]  zip -q -r data.zip /opt/install 参数作用:不显示指令执行过程(-q).递归处理,将指定目录下的所有文件和子目录一并处理(-r) [参数] -A:调整可执行的 ...

  6. linux zip压缩包大小,Linux中巧用zip命令压缩和解压缩文件

    在Windows中,我们用得最多的解压缩软件就是WinRAR了,这个软件对我们实现解压缩非常方便.但是如果在Linux系统中,我们还可以尝试用命令来实现对文件的解压缩,这篇文章主要介绍在Linux中用 ...

  7. Linux 解压缩文件之zip命令

    以下内容来自Linux命令大全 zip命令 zip命令可以用来解压缩文件,或者对文件进行打包操作.zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有".zip"扩展名的压缩 ...

  8. Linux常用基础命令(很全)

    Linux常用基础命令 Linux命令格式 Linux 常见用户管理命令 创建新用户 Linux文件及目录管理命令 绝对路径和相对路径 cd命令 ls命令 pwd命令 mkdir命令 touch命令 ...

  9. linux zip 命令详解

    功能说明:压缩文件.  语 法:zip [-AcdDfFghjJKlLmoqrSTuvVwXyz$][-b <工作目录>][-ll][-n <字尾字符串>][-t <日期 ...

最新文章

  1. 辽师836c语言真题,2018年武汉科技大学考研真题硕士研究生入学考试试题
  2. 如何安全设置无线路由
  3. 业务智能 ETL 设计实施策略(转载)
  4. extjs获取焦点和失去焦点_ios输入框(input,select,textarea)失去焦点,页面不归位...
  5. 浅谈最小生成树的算法思路(二)Kruskal算法
  6. -webkit-gradient webkit内核浏览器的Linear Gradients (线性渐变) -Css3演示
  7. Linux(centOS)手动安装删除Apache+MySQL+PHP+Memcached原创无错版
  8. 苹果今年将为iPhone采购1.72亿块OLED屏幕 六成用于iPhone 13
  9. VMware 禁用虚拟内存文件,提升虚拟机响应速度 .
  10. 关于空白模板插件的使用
  11. CCF201712试题
  12. 远离魔咒,见微知著,打造崭新的罗浮宫
  13. 常见测试用例设计方法1---等价类划分
  14. matlab进化树的下载,MEGA进化树下载
  15. cosx sinx 泰勒展开 C++
  16. 基因融合检测:1、基因融合数据库、融合检测软件汇总
  17. Codeforces Round #660 (Div. 2) B. Captain Flint and a Long Voyage
  18. 社群裂变营销“肩负”着公司百分之九十的流量
  19. 每周分享第 10 期
  20. 博途数据类型wstring怎么用_在 STEP 7 (TIA 博途) 中,如何使用用户自定义数据类型 (UDT)?...

热门文章

  1. IQ正交调制及星座图
  2. 码农的自我修养 - ARM V9架构的巨大价值
  3. 对谈 | 创新与进化——当开源接受SaaS
  4. 如何在手机上收发邮件?
  5. 新乡学院二批计算机类分数线,新乡学院录取分数线2021是多少分(附历年录取分数线)...
  6. 无法解析的外部符号__imp__fprintf和 __imp____iob_func,SDL2
  7. Python作业“骰子游戏”
  8. JS设计模式之代理模式-虚拟代理
  9. 苹果手机怎么设置录屏功能_苹果手机怎么录屏 苹果手机录屏功能开启/使用教程...
  10. 化合物筛选“杀手锏”:高质量化合物库+一站式虚拟筛选,这里都备齐了