zip:打包和压缩文件

    zip压缩格式是Windows与Linux等多平台通用的压缩格式。和gzip命令相比,zip命令压缩文件不仅不会删除源文件,而且还可以压缩目录。
 

zip命令的参数选项及说明

 
-r    将指定目录下的所有文件和子目录一并压缩
-x    压缩文件时排除某个文件
-q    不显示压缩信息
 

压缩文件

[root@cs6 tmp]# cp /etc/services .
[root@cs6 tmp]# ll -h services
-rw-r--r--. 1 root root 626K May 13 00:35 services [root@cs6 tmp]# zip services.zip ./services #<==格式:zip 压缩包名 被压缩的文件。
adding: services (deflated 80%) #<==deflated压缩率。
[root@cs6 tmp]# ll -h services*
-rw-r--r--. 1 root root 626K May 13 00:35 services
-rw-r--r--. 1 root root 125K May 13 00:38 services.zip

压缩目录

[root@cs6 tmp]# cd /
[root@cs6 /]# zip tmp.zip ./tmp/
adding: tmp/ (stored 0%)
[root@cs6 /]# zip -r tmp.zip ./tmp/
updating: tmp/ (stored 0%)
adding: tmp/anaconda-ks.cfg (deflated 38%)
adding: tmp/install.log (deflated 71%)
adding: tmp/yum.log (stored 0%)
....
adding: tmp/html/6.html (stored 0%)
adding: tmp/html/10.html (stored 0%)
adding: tmp/html/1.html (stored 0%)
adding: tmp/html/8.html (stored 0%)
adding: tmp/services.zip (stored 0%)
adding: tmp/services (deflated 80%)

排除压缩

[root@cs6 /]# zip -r tmp.zip ./tmp/ -x tmp
tmp/ tmp.zip
[root@cs6 /]# zip -r tmp.zip ./tmp/ -x tmp/services.zip
updating: tmp/ (stored 0%)
updating: tmp/anaconda-ks.cfg (deflated 38%)
updating: tmp/install.log (deflated 71%)
updating: tmp/yum.log (stored 0%)
updating: tmp/.ICE-unix/ (stored 0%)
updating: tmp/lewen.log (deflated 50%)
......
updating: tmp/html/8.html (stored 0%)
updating: tmp/services (deflated 80%)
[root@cs6 /]#

unzip:解压zip文件

    unzip命令可以解压zip命令或其他压缩软件压缩的zip格式的文件。
-l    不解压显示压缩包内容
-o    解压时不提示是否覆盖文件
-d    指定解压目录
-v    解压时显示详细信息
 

查看压缩文件。

[root@cs6 /]# unzip -l tmp.zip
Archive: tmp.zip
Length Date Time Name
--------- ---------- ----- ----
0 05-13-2019 00:38 tmp/
1092 05-05-2019 23:12 tmp/anaconda-ks.cfg
8081 05-05-2019 23:12 tmp/install.log
0 05-05-2019 23:10 tmp/yum.log
0 05-11-2019 17:56 tmp/.ICE-unix/
150 05-12-2019 22:54 tmp/lewen.log
3384 05-05-2019 23:11 tmp/install.log.syslog
9068168 05-12-2019 18:46 tmp/etc.tar.gz
0 05-12-2019 18:19 tmp/html/
......
0 05-12-2019 18:19 tmp/html/6.html
0 05-12-2019 18:19 tmp/html/10.html
0 05-12-2019 18:19 tmp/html/1.html
0 05-12-2019 18:19 tmp/html/8.html
127362 05-13-2019 00:38 tmp/services.zip
641020 05-13-2019 00:35 tmp/services
--------- -------
9849257 23 files

常规解压文件的例子

[root@cs6 /]# unzip tmp.zip
Archive: tmp.zip
replace tmp/anaconda-ks.cfg? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: tmp/anaconda-ks.cfg
replace tmp/install.log? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: tmp/install.log
replace tmp/yum.log? [y]es, [n]o, [A]ll, [N]one, [r]ename: y [root@cs6 /]# unzip -v tmp.zip #<==解压时显示一些信息。
Archive: tmp.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 05-13-2019 00:38 00000000 tmp/
1092 Defl:N 679 38% 05-05-2019 23:12 0cd9b8ec tmp/anaconda-ks.cfg
8081 Defl:N 2366 71% 05-05-2019 23:12 2254ab8c tmp/install.log
150 Defl:N 75 50% 05-12-2019 22:54 6195ad09 tmp/lewen.log
3384 Defl:N 569 83% 05-05-2019 23:11 0c331784 tmp/install.log.syslog
9068168 Defl:N 7955263 12% 05-12-2019 18:46 da37147b tmp/etc.tar.gz
......
0 Stored 0 0% 05-12-2019 18:19 00000000 tmp/html/8.html
127362 Stored 127362 0% 05-13-2019 00:38 859b286f tmp/services.zip
641020 Defl:N 127196 80% 05-13-2019 00:35 33bd3343 tmp/services
-------- ------- --- -------
9849257 8213510 17% 23 files [root@cs6 /]# unzip -o tmp.zip #<==解压时不提示是否覆盖。
Archive: tmp.zip
inflating: tmp/anaconda-ks.cfg
inflating: tmp/install.log
inflating: tmp/install.log.syslog
inflating: tmp/etc.tar.gz
.....
extracting: tmp/html/1.html
extracting: tmp/html/8.html
extracting: tmp/services.zip
inflating: tmp/services

指定解压目录解压文件

[root@cs6 /]# unzip -d /tmp tmp.zip    #<==可以使用-d选项接目录来指定解压目录
Archive: tmp.zip
creating: /tmp/tmp/
inflating: /tmp/tmp/anaconda-ks.cfg
inflating: /tmp/tmp/install.log
extracting: /tmp/tmp/yum.log
creating: /tmp/tmp/.ICE-unix/
....
extracting: /tmp/tmp/html/1.html
extracting: /tmp/tmp/html/8.html
extracting: /tmp/tmp/services.zip
inflating: /tmp/tmp/services [root@cs6 /]# tree /tmp
/tmp
├── anaconda-ks.cfg
├── etc.tar.gz
├── html
│ ├── 10.html
│ ├── 1.html
│ ├── 2.html
│ ├── 3.html
│ ├── 4.html
│ ├── 5.html
│ ├── 6.html
.... │ ├── services
│ ├── services.zip
│ └── yum.log
└── yum.log 7 directories, 36 files
 

6.3-4 zip、unzip的更多相关文章

  1. linux下压缩与解压(zip、unzip、tar)详解

    linux下压缩与解压(zip.unzip.tar)详解 2012-05-09 13:58:39| 分类: linux | 标签:linux zip unzip tar linux命令详解 |举报|字 ...

  2. 【转载】 Linux常用命令: zip、unzip 压缩和解压缩命令

    Linux常用命令: zip.unzip 压缩和解压缩命令   Linux常用命令: zip.unzip 压缩和解压缩命令 zip的用法 基本用法是: zip [参数] [打包后的文件名] [打包的目 ...

  3. Linux命令-压缩解压命令:zip、unzip

    zip [选项] [压缩后文件名] [压缩前的文件或者目录名称] -r表示压缩目录(recursion 递归) rm -rf * 删除当前目录下面的所有文件,也包括目录和子目录ls cp /etc/s ...

  4. Linux常用命令: zip、unzip 压缩和解压缩命令

    zip基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] 常用参数: -a 将文件转成ASCII模式 -F 尝试修复损坏的压缩文件 -h 显示帮助界面 -m 将文件压缩之后,删除源 ...

  5. tar、zip 、unzip 打包与压缩 (参考:http://pengyl.blog.51cto.com/5591604/1191197)

    通常都是先通过tar命令将多个文件或目录打包成一个包文件,然后再通过gzip或bzip2进行压缩,如*.tar.gz和*.tar.bz2就属于这种先打包再压缩的文件.在实际使用中,一般都是通过tar命 ...

  6. Linux(CentOS7)安装zip、unzip命令

    安装命令: yum install -y unzip zip

  7. PHP的zip、unzip类详解

    1.打开一个ZIP包,用于读取.写入或修改 open(string $filename [, int $flags]) $filename - 文件名 $flags - 打开模式 ZIPARCHIVE ...

  8. Linux中gzip、bzip2、zip、unzip、tar使用介绍

    压缩解压缩命令介绍.gz 压缩为gzip文件.bz2 压缩为bzip2文件.tar 打包文件,将多个文件合并成一个目录.tar.gz 先打成tar包,再压缩为gzip文件.tar.bz2 先打成tar ...

  9. Linux下的压缩zip,解压缩unzip命令详解及实例

    实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip ====================== ...

随机推荐

  1. 关于C语言解决汉诺塔(hanoi)问题

    C语言解决汉诺塔问题 汉诺塔是典型的递归调用问题: hanoi简介:印度教的主神梵天在创造世界的时候,在其中一根针上从下到上地穿好了由大到小的64片金片,这就是所谓的汉诺塔.不论白天黑夜,总有一个僧侣 ...

  2. Linux 基础命令 命令进阶

    Linux命令格式:命令 选项 参数 (大部分命令是这个格式) 注意: 1.命令区分大小写 2.短选项可以合并   长选项不能合并 如 : 短选项 -l  -h 可以合并为 -lh 长选项  不能合并 ...

  3. 2. IntelliJ Idea 常用快捷键列表

    Ctrl+E,最近的文件 Ctrl+Shift+E,最近更改的文件 Shift+Click,可以关闭文件 Ctrl+[ OR ],可以跑到大括号的开头与结尾 Ctrl+F12,可以显示当前文件的结构 ...

  4. kubernetes集群centos7初始化

    设置系统主机名以及 Host 文件的相互解析 hostnamectl set-hostname k8s-master01 安装依赖包 yum -y install wget net-tools nfs ...

  5. 473. Matchsticks to Square

    Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...

  6. Bootstrap工具包--用于响应式布局和移动设备优先的web项目

    Bootstrap是用于前端开发的工具包,是一个css/html框架 用于响应式布局和移动设备优先的web项目 响应式布局--一个网站能兼容多个终端 有很多版本:v3,v4,v5   三个没啥区别  ...

  7. 【swagger】 swagger-ui的升级版swagger-bootstrap-ui

    swagger-bootstrap-ui是基于swagger-ui做了一些优化拓展: swagger-ui的界面: swagger-bootstrap-ui界面: 相比于原生的swagger-ui , ...

  8. git 避免重复输入用户名密码问题解决

    "store" 模式会将凭证用明文的形式存放在磁盘中,并且永不过期. 这意味着除非你修改了你在 Git 服务器上的密码,否则你永远不需要再次输入你的凭证信息. 这种方式的缺点是你的 ...

  9. SVCHOST启动服务实战

    本文转载自:https://blog.csdn.net/huanglong8/article/details/70666987 转载出处: https://sanwen8.cn/p/2cenbHs.h ...

  10. Linux日志分析和管理

    目录 日志的作用.分类.管理.轮转和级别 rsyslog服务 Journal守护进程 /var/log下相关的日志文件 日志服务器的建立 日志的作用.分类.管理.轮转和级别 日志的作用: 用于记录系统 ...