Linux 命令(文件和目录管理 - zip/unzip)
来源:互联网 发布:windows xp系统是什么 编辑:程序博客网 时间:2024/06/08 14:32
简述
zip/unzip 是 Linux 中广泛使用的压缩/解压缩程序,zip 命令用来将文件压缩为常用的 zip 格式(扩展名为 .zip);unzip 命令则用来解压缩 zip 文件。
- 简述
- zip
- 命令介绍
- 命令选项
- 使用范例
- unzip
- 命令介绍
- 命令选项
- 使用范例
zip
命令介绍
命令名称
zip基本语法
zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption ...] [-b path] [-n suffixes] [-t date] [-tt date] [zipfile [file ...]] [-xi list]
功能描述
打包和压缩文件
命令选项
-A
调整可执行的自动解压缩文件 [-b path]
指定暂时存放文件的目录 -c
为每个被压缩的文件加上注释 -d
从压缩文件内删除指定文件 -f
此选项的效果和指定 -u 选项类似,但不仅更新既有文件,如果某些文件原本不存在于压缩文件内,使用此选项会一并将其加入压缩文件中 -F
尝试修复损坏的压缩文件 -g
将文件压缩后附加在既有的压缩文件之后,而非另行建立新的压缩文件 -h
在线帮助 -j
只保存文件名称及其内容,而不存放任何目录名称 -J
删除压缩文件前面不必要的数据 -k
使用 MS-DOS 兼容格式的文件名称 -l
压缩文件时,把 LF 字符置换成 LF+CR 字符 -ll
压缩文件时,把 LF+CR 字符置换成 LF 字符 -L
显示版权信息符 -m
将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中 [-n suffixes]
不压缩具有特定字尾字符串的文件 -o
将压缩文件内的所有文件的最新变动时间设置为压缩时候的时间 -q
安静模式,压缩时不显示命令的执行过程 -r
递归处理,将指定目录下的所有子目录以及文件一并处理 -S
包含系统文件和隐藏文件 [-t date]
将压缩文件的最后修改日期设为指定的日期,日期格式为:mmddyyyy-x -T
检查备份文件内的每个文件是否正确无误 -u
更换较新的文件到压缩文件内 -v
显示命令执行过程或版本信息 -V
保存 VMS 操作系统的文件属性 -w
在文件名称里加入版本编号,此选项仅在 VMS 操作系统下有效 [-x list]
指定不要处理 .zip 压缩文件中的哪些文件 -X
不保存额外的文件属性 -y
直接保存符号连接,而非该连接所指向的文件,本参数仅在 UNIX 之类的系统下有效 -z
替压缩文件加上注释 -$
保存第一个被压缩文件所在磁盘的卷册名称 [- 压缩效率]
压缩效率是一个介于 1-9 的数值使用范例
1.压缩文件
将文件 debug.log 压缩为 debug.zip:
[wang@localhost doc]$ zip debug.zip debug.log adding: debug.log (deflated 98%)[wang@localhost doc]$ ls -l debug.zip -rw-rw-r--. 1 wang wang 8388 10月 8 15:37 debug.zip
2.压缩率为 8
[wang@localhost doc]$ zip debug2.zip -8 debug.log adding: debug.log (deflated 98%)[wang@localhost doc]$ ls -l debug2.zip -rw-rw-r--. 1 wang wang 7747 10月 8 15:38 debug2.zip
3.压缩目录
选项 -r 表示递归压缩子目录下所有文件,将目录 c 压缩为 c.zip:
[wang@localhost doc]$ zip -r c.zip c adding: c/ (stored 0%) adding: c/hello.c (stored 0%) adding: c/qt5_cadaques.pdf (deflated 4%) adding: c/QmlBook-In-Chinese.pdf (deflated 21%) adding: c/qwt-6.1.1.pdf (deflated 5%)
将目录 c 和文件 debug.log 压缩成为 cDebug.zip:
[wang@localhost doc]$ zip -r cDebug.zip c debug.log adding: c/ (stored 0%) adding: c/hello.c (stored 0%) adding: c/qt5_cadaques.pdf (deflated 4%) adding: c/QmlBook-In-Chinese.pdf (deflated 21%) adding: c/qwt-6.1.1.pdf (deflated 5%) adding: debug.log (deflated 98%)
4.从压缩文件内删除指定文件
# 查看 c.zip 中的内容[wang@localhost doc]$ unzip -v c.zip Archive: c.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 15:19 00000000 c/ 60 Stored 60 0% 09-29-2016 11:05 1c70977f c/hello.c 7484327 Defl:N 7156991 4% 12-16-2015 09:24 419f4101 c/qt5_cadaques.pdf 7283461 Defl:N 5778374 21% 12-14-2015 11:19 a2ef8f24 c/QmlBook-In-Chinese.pdf 2604948 Defl:N 2466270 5% 01-18-2016 19:06 6dae3792 c/qwt-6.1.1.pdf-------- ------- --- -------17372796 15401695 11% 5 files# 删除 c.zip 中的文件 c/QmlBook-In-Chinese.pdf[wang@localhost doc]$ zip -d c.zip c/QmlBook-In-Chinese.pdf deleting: c/QmlBook-In-Chinese.pdf# 再次查看 c.zip 中的内容[wang@localhost doc]$ unzip -v c.zip Archive: c.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 15:19 00000000 c/ 60 Stored 60 0% 09-29-2016 11:05 1c70977f c/hello.c 7484327 Defl:N 7156991 4% 12-16-2015 09:24 419f4101 c/qt5_cadaques.pdf 2604948 Defl:N 2466270 5% 01-18-2016 19:06 6dae3792 c/qwt-6.1.1.pdf-------- ------- --- -------10089335 9623321 5% 4 files
显然,使用 -d 选项删除指定文件后,c.zip 中的文件数从之前的 5 个变为 4 个。
5.向压缩文件中添加指定文件
使用 -m 选项将文件压缩并加入至压缩文件后,原始文件将被删除。
# 查看 c.zip 中的内容[wang@localhost doc]$ unzip -v c.zip Archive: c.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 15:19 00000000 c/ 60 Stored 60 0% 09-29-2016 11:05 1c70977f c/hello.c 7484327 Defl:N 7156991 4% 12-16-2015 09:24 419f4101 c/qt5_cadaques.pdf 2604948 Defl:N 2466270 5% 01-18-2016 19:06 6dae3792 c/qwt-6.1.1.pdf-------- ------- --- -------10089335 9623321 5% 4 files# 将文件 debug.log 压缩并加入至压缩文件 c.zip后,删除原始文件 debug.log[wang@localhost doc]$ zip -m c.zip debug.log adding: debug.log (deflated 98%)[wang@localhost doc]$ unzip -v c.zip Archive: c.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 15:19 00000000 c/ 60 Stored 60 0% 09-29-2016 11:05 1c70977f c/hello.c 7484327 Defl:N 7156991 4% 12-16-2015 09:24 419f4101 c/qt5_cadaques.pdf 2604948 Defl:N 2466270 5% 01-18-2016 19:06 6dae3792 c/qwt-6.1.1.pdf 368640 Defl:N 8220 98% 09-30-2016 16:23 7c861caf debug.log-------- ------- --- -------10457975 9631541 8% 5 files
6.压缩文件时排除某个文件
# 查看目录树,包含两个文件[wang@localhost doc]$ tree linux/linux/├── hello.sh└── linux-program.pdf0 directories, 2 files# 压缩时,排除文件 linux/hello.sh[wang@localhost doc]$ zip -r linux.zip linux -x linux/hello.sh adding: linux/ (stored 0%) adding: linux/linux-program.pdf (deflated 2%)# 查看 linux.zip 中的内容 [wang@localhost doc]$ unzip -v linux.zip Archive: linux.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 16:26 00000000 linux/33921784 Defl:N 33208837 2% 06-07-2016 11:02 e968a493 linux/linux-program.pdf-------- ------- --- -------33921784 33208837 2% 2 files
unzip
命令介绍
命令名称
unzip基本语法
unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] [-x xfile(s) ...] [-d exdir]
功能描述
列出、测试、提取 zip 文件中的压缩文件
命令选项
-c
将解压缩的结果显示到屏幕上,并对字符做适当的转换 -f
更新现有文件 -l
显示压缩文件内所包含的文件 -p
与 -c 选项类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换 -t
检查压缩文件是否正确,但不解压 -u
与 -f 选项类似,但是除了更新现有的文件外,也会将压缩文件中的其他文件解压缩到目录中 -v
执行时显示详细的信息,或查看压缩文件目录,但不解压。 -z
仅显示压缩文件的备注文字 -a
对文本文件进行必要的字符转换 -b
不要对文本文件进行字符转换 -C
压缩文件中的文件名称区分大小写 -j
不处理压缩文件中原有的目录路径 -L
将压缩文件中的全部文件名改为小写 -M
将输出结果送到 more 程序处理 -n
解压缩时不覆盖原有文件 -o
不必先询问用户,unzip 执行后覆盖原有文件 -q
执行时不显示任何信息 -s
将文件名中的空白字符转换为底线字符 -V
保留 VMS 的文件版本信息 -X
解压缩时同时回存文件原来的 UID/GID file[.zip]
指定 .zip 压缩文件 [file(s) ...]
指定要处理 .zip 压缩文件中的哪些文件 [-x xfile(s) ...]
指定不要处理 .zip 压缩文件中的哪些文件 [-d exdir]
指定文件解压缩后所要存储的目录 -Z
unzip -Z 等于执行 zipinfo 指令使用范例
1.将压缩文件解压缩至当前目录下
如果当前目录存在同名文件,会进行询问“是否替换?”。
[wang@localhost doc]$ unzip c.zip Archive: c.zipreplace c/hello.c? [y]es, [n]o, [A]ll, [N]one, [r]ename: N
2.解压缩时不覆盖原有文件
[wang@localhost doc]$ unzip -n c.zip Archive: c.zip
3.解压缩时覆盖原有文件
不必询问用户,unzip 执行后覆盖原有文件
[wang@localhost doc]$ unzip -o c.zip Archive: c.zip extracting: c/hello.c inflating: c/qt5_cadaques.pdf inflating: c/qwt-6.1.1.pdf inflating: debug.log
4.将压缩文件解压缩至指定目录下
[wang@localhost doc]$ unzip -n c.zip -d /tmp/Archive: c.zip creating: /tmp/c/ extracting: /tmp/c/hello.c inflating: /tmp/c/qt5_cadaques.pdf inflating: /tmp/c/qwt-6.1.1.pdf inflating: /tmp/debug.log
5.查看压缩文件目录(不解压)
[wang@localhost doc]$ unzip -v c.zip Archive: c.zip Length Method Size Cmpr Date Time CRC-32 Name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 10-08-2016 15:19 00000000 c/ 60 Stored 60 0% 09-29-2016 11:05 1c70977f c/hello.c 7484327 Defl:N 7156991 4% 12-16-2015 09:24 419f4101 c/qt5_cadaques.pdf 2604948 Defl:N 2466270 5% 01-18-2016 19:06 6dae3792 c/qwt-6.1.1.pdf 368640 Defl:N 8220 98% 09-30-2016 16:23 7c861caf debug.log-------- ------- --- -------10457975 9631541 8% 5 files
- Linux 命令(文件和目录管理 - zip/unzip)
- Linux下zip和unzip解压缩文件命令
- linux 解压缩zip文件 unzip 命令详解
- linux zip/unzip命令
- linux zip/unzip命令
- linux zip/unzip命令
- linux zip/unzip命令
- linux zip/unzip命令
- linux zip/unzip命令
- Linux zip/unzip 命令
- linux zip/unzip命令
- linux zip/unzip命令
- Linux命令ZIP/UNZIP
- linux zip/unzip命令
- linux zip/unzip命令
- linux zip/unzip命令
- Linux中使用unzip命令解压缩zip文件到特定目录
- zip命令和unzip命令
- 第5章 路由事件(5)——自定义路由事件
- 在CentOS下搭建自己的Git服务器
- 使用百度API实现轨迹回放
- 十大经典排序整理
- OGL多边形或二次曲面分格化(Tessellation曲面软件细分技术)
- Linux 命令(文件和目录管理 - zip/unzip)
- 第五周,C语言项目1,求正差值
- 第五周 矩形长宽求面积
- 第五周:Raptor:三色球问题
- Servlet规范总结
- iOS字体及样式
- [JAVA学习笔记-60]ByteBuffer的分配方式的比较
- OpenCV读取的图片从BGR转换为RGB
- Pow(x, n)