unzip

unzip命令是用于.zip格式文件的解压缩工具,unzip命令将列举、测试或从zip格式存档中提取文件,这种文件一般坐落MS-DOS系统上。

默认行为(就是没有选项)是从指定的ZIP存档中提取所有的文件到当前目录(及其下边的子目录)。一个配套程序zip(1L)创建ZIP存档;这两个程序都与PKWARE的PKZIP和PKUNZIP为MS-DOS创建的存档文件兼容linux zip压缩命令,但许多情况下,程序选项或默认行为是不同的。

句型

unzip【选项】【参数】

参数

-c将解压缩的结果显示到屏幕上小型linux系统,并对字符做适当的转换。

-f更新现有的文件。

-l显示压缩文件内所包含的文件。

-p与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换。

-t检测压缩文件是否正确。

-u与-f参数类似linux zip压缩命令,而且不仅更新现有的文件外linux漏洞扫描,也会将压缩文件中的其他文件解压缩到目录中。

-v执行是时显示详尽的信息。

-z仅显示压缩文件的备注文字。

-a对文本文件进行必要的字符转换。

-b不要对文本文件进行字符转换。

-C压缩文件中的文件名称分辨大小写。

-j不处理压缩文件中原有的目录路径。

-L将压缩文件中的全部文件名改为大写。

-M将输出结果送到more程序处理。

-n解压缩时不要覆盖原有的文件。

-o不必先寻问用户,unzip执行后覆盖原有文件。

-P使用zip的密码选项。

-q执行时不显示任何信息。

-s将文件名中的空白字符转换为底线字符。

-V保留VMS的文件版本信息。

-X解压缩时同时回存文件原先的UID/GID。

[.zip文件]指定.zip压缩文件。

[文件]指定要处理.zip压缩文件中的什么文件。

linux zip压缩命令_压缩命令tar_压缩命令tar.gz

-d指定文件解压缩后所要储存的目录。

-x指定不要处理.zip压缩文件中的什么文件。

-Zunzip-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压缩的文件进行最简单解压。

压缩命令tar_压缩命令tar.gz_linux 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

Author

这篇优质的内容由TA贡献而来

刘遄

《Linux就该这么学》书籍作者,RHCA认证架构师,教育学(计算机专业硕士)。

发表回复