unzip
unzip命令是用于.zip格式文件的解压缩工具 ,unzip命令将列出、测试或从zip格式存档中提取文件,这些文件通常位于MS-DOS系统上。
默认行为(就是没有选项)是从指定的ZIP存档中提取所有的文件到当前目录(及其下面的子目录)。一个配套程序zip(1L)创建ZIP存档;这两个程序都与PKWARE的PKZIP和PKUNZIP为MS-DOS创建的存档文件兼容,但许多情况下,程序选项或默认行为是不同的。
语法
unzip 【选项】 【参数】
参数
-c 将解压缩的结果显示到屏幕上,并对字符做适当的转换。
-f 更新现有的文件。
-l 显示压缩文件内所包含的文件。
-p 与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换。
-t 检查压缩文件是否正确。
-u 与-f参数类似,但是除了更新现有的文件外,也会将压缩文件中的其他文件解压缩到目录中。
-v 执行是时显示详细的信息。
-z 仅显示压缩文件的备注文字。
-a 对文本文件进行必要的字符转换。
-b 不要对文本文件进行字符转换。
-C 压缩文件中的文件名称区分大小写。
-j 不处理压缩文件中原有的目录路径。
-L 将压缩文件中的全部文件名改为小写。
-M 将输出结果送到more程序处理。
-n 解压缩时不要覆盖原有的文件。
-o 不必先询问用户,unzip执行后覆盖原有文件。
-P<密码> 使用zip的密码选项。
-q 执行时不显示任何信息。
-s 将文件名中的空白字符转换为底线字符。
-V 保留VMS的文件版本信息。
-X 解压缩时同时回存文件原来的UID/GID。
[.zip文件] 指定.zip压缩文件。
[文件] 指定要处理.zip压缩文件中的哪些文件。
-d<目录> 指定文件解压缩后所要存储的目录。
-x<文件> 指定不要处理.zip压缩文件中的哪些文件。
-Z unzip -Z等于执行zipinfo指令。
常用实例
首先创建用于测试的文件
[root@linus ~]# zip -qr var.zip /var/
[root@linus ~]# zip -qr boot.zip /boot/
[root@linus ~]# zip -qr root.zip /root/
[root@linus ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg var.zip
boot.zip root.zip
注:直接使用 unzip 文件名 即可对zip压缩的文件进行最简单解压。
例1:检查root.zip文件的完整性
[root@linus ~]# unzip -t root.zip
Archive: root.zip
testing: root/ OK
testing: root/.bash_logout OK
testing: root/.bash_profile OK
testing: root/.bashrc OK
testing: root/.cshrc OK
testing: root/.tcshrc OK
testing: root/anaconda-ks.cfg OK
testing: root/.cache/ OK
testing: root/.cache/dconf/ OK
testing: root/.cache/dconf/user OK
testing: root/.cache/abrt/ OK
testing: root/.cache/abrt/lastnotification OK
testing: root/.dbus/ OK
testing: root/.dbus/session-bus/ OK
testing: root/.dbus/session-bus/fbeeec90c86642ea89de04d30fd9ec03-9 OK
testing: root/initial-setup-ks.cfg OK
testing: root/.config/ OK
testing: root/.config/abrt/ OK
testing: root/.bash_history OK
testing: root/.viminfo OK
testing: root/var.zip OK
testing: root/boot.zip OK
No errors detected in compressed data of root.zip.
例2:显示压缩root.zip文件内所包含的文件
[root@linus ~]# unzip -l root.zip
Archive: root.zip
Length Date Time Name
--------- ---------- ----- ----
0 02-14-2020 00:05 root/
18 12-29-2013 10:26 root/.bash_logout
176 12-29-2013 10:26 root/.bash_profile
176 12-29-2013 10:26 root/.bashrc
100 12-29-2013 10:26 root/.cshrc
129 12-29-2013 10:26 root/.tcshrc
1761 12-10-2019 19:56 root/anaconda-ks.cfg
0 12-12-2019 18:17 root/.cache/
0 12-10-2019 20:04 root/.cache/dconf/
2 12-10-2019 20:04 root/.cache/dconf/user
0 02-14-2020 00:03 root/.cache/abrt/
11 02-14-2020 00:03 root/.cache/abrt/lastnotification
0 12-10-2019 20:04 root/.dbus/
0 12-10-2019 20:04 root/.dbus/session-bus/
463 12-10-2019 20:04 root/.dbus/session-bus/fbeeec90c86642ea89de04d30fd9ec03-9
1809 12-10-2019 20:05 root/initial-setup-ks.cfg
0 12-12-2019 18:17 root/.config/
0 12-12-2019 18:17 root/.config/abrt/
432 12-12-2019 18:24 root/.bash_history
1489 12-12-2019 18:24 root/.viminfo
39093292 02-14-2020 00:04 root/var.zip
143739224 02-14-2020 00:05 root/boot.zip
--------- -------
182839082 22 files
例3:解压时显示详细信息,并覆盖原有文件
[root@linus ~]# unzip -vo root.zip
Archive: root.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 02-14-2020 00:05 00000000 root/
18 Stored 18 0% 12-29-2013 10:26 ef677b9f root/.bash_logout
176 Defl:N 143 19% 12-29-2013 10:26 ec284a1e root/.bash_profile
176 Defl:N 125 29% 12-29-2013 10:26 adf27baa root/.bashrc
100 Defl:N 76 24% 12-29-2013 10:26 f4fbd29d root/.cshrc
129 Defl:N 101 22% 12-29-2013 10:26 8101bd50 root/.tcshrc
1761 Defl:N 937 47% 12-10-2019 19:56 f7df0984 root/anaconda-ks.cfg
0 Stored 0 0% 12-12-2019 18:17 00000000 root/.cache/
0 Stored 0 0% 12-10-2019 20:04 00000000 root/.cache/dconf/
2 Stored 2 0% 12-10-2019 20:04 41d912ff root/.cache/dconf/user
0 Stored 0 0% 02-14-2020 00:03 00000000 root/.cache/abrt/
11 Stored 11 0% 02-14-2020 00:03 4fee9543 root/.cache/abrt/lastnotification
0 Stored 0 0% 12-10-2019 20:04 00000000 root/.dbus/
0 Stored 0 0% 12-10-2019 20:04 00000000 root/.dbus/session-bus/
463 Defl:N 307 34% 12-10-2019 20:04 3d13ddf2 root/.dbus/session-bus/fbeeec90c86642ea89de04d30fd9ec03-9
1809 Defl:N 956 47% 12-10-2019 20:05 d753b912 root/initial-setup-ks.cfg
0 Stored 0 0% 12-12-2019 18:17 00000000 root/.config/
0 Stored 0 0% 12-12-2019 18:17 00000000 root/.config/abrt/
432 Defl:N 212 51% 12-12-2019 18:24 e8b0de6c root/.bash_history
1489 Defl:N 449 70% 12-12-2019 18:24 54a97f69 root/.viminfo
39093292 Stored 39093292 0% 02-14-2020 00:04 5b45c027 root/var.zip
143739224 Stored 143739224 0% 02-14-2020 00:05 e6ac17d7 root/boot.zip
-------- ------- --- -------
182839082 182835853 0% 22 files
例4:不显示信息解压var.zip文件,并指定文件解压缩后所要存储的目录
[root@linus ~]# unzip -q var.zip -d /backup
[root@linus ~]# ls /backup/
var