命令简介

unzip 命令用于解压由zip命令压缩的压缩包文件。

#Debian/Ubuntu安装
apt-get install unzip

#CentOS安装
[root@centos7 ~]# unzip 
-bash: unzip: command not found
[root@centos7 ~]# yum install unzip -y

语法格式

unzip [ OPTIONS ] file[.zip] [file(s) ...]

选项说明

-c  #将解压缩的结果输出,并对字符做适当的转换
-f  #更新现有的文件
-l  #列出压缩文件内所包含的文件
-p  #将解压缩的结果显示到屏幕上,但不执行任何的转换
-t  #检查压缩文件是否正确;
-u  #除了更新现有的文件外,也会将压缩文件中的其他文件解压缩到目录中
-v  #显示详细的信息
-z  #仅显示压缩文件的备注信息
-a  #对文本文件进行必要的字符转换
-b  #不对文本文件进行字符转换
-C  #压缩文件名称区分大小写
-j  #不处理压缩文件中原有的目录路径
-L  #将压缩文件中的全部文件名改为小写
-M  #将输出结果再交给more程序处理
-n  #解压缩时不覆盖原有的文件
-o  #unzip执行后覆盖原有的文件,不提示
-P<密码>  #使用zip的密码选项
-q  #不显示任何命令执行过程信息
-s  #将文件名中的空白字符转换为底线字符
-d<目录>  #将解压缩后存至指定的目录下
-x<文件>  #指定不要处理.zip压缩文件中的哪些文件
-Z  #unzip-Z相当于执行zipinfo命令

应用举例

解压一个文件

[root@centos7 testdir]# unzip mingongge.zip

查看一个压缩文件但不解压

[root@centos7 testdir]# unzip -v mingongge.zip 
Archive:  mingongge.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
      59  Stored       59   0% 01-16-2021 12:15 b32621da  cest.txt.gz
      57  Stored       57   0% 01-16-2021 12:12 cbda1ce8  cuttest.txt.gz
       0  Stored        0   0% 01-16-2021 16:18 00000000  dir/
       0  Stored        0   0% 01-16-2021 16:18 00000000  file
      81  Stored       81   0% 01-16-2021 09:55 da9f2476  mingongge1.txt.gz
      51  Stored       51   0% 01-16-2021 03:36 8fdf382e  mingongge2.txt.gz
      87  Stored       87   0% 01-16-2021 09:59 982ab7bb  mingongge.txt.md5.gz
      65  Stored       65   0% 01-16-2021 10:19 17350869  sort.cut.txt.gz
--------          -------  ---                            -------
     400              400   0%                            8 files

指定解压后的文件存放目录

[root@centos7 testdir]# unzip -n mingongge.zip -d /tmp/
Archive:  mingongge.zip
 extracting: /tmp/cest.txt.gz        
 extracting: /tmp/cuttest.txt.gz     
   creating: /tmp/dir/
 extracting: /tmp/file               
 extracting: /tmp/mingongge1.txt.gz  
 extracting: /tmp/mingongge2.txt.gz  
 extracting: /tmp/mingongge.txt.md5.gz  
 extracting: /tmp/sort.cut.txt.gz    
[root@centos7 testdir]# ll /tmp/
total 24
-rw-r--r-- 1 root root 59 Jan 16 12:15 cest.txt.gz
-rw-r--r-- 1 root root 57 Jan 16 12:12 cuttest.txt.gz
drwxr-xr-x 2 root root  6 Jan 16 16:18 dir
-rw-r--r-- 1 root root  0 Jan 16 16:18 file
-rw-r--r-- 1 root root 81 Jan 16 09:55 mingongge1.txt.gz
-rw-r--r-- 1 root root 51 Jan 16 03:36 mingongge2.txt.gz
-rw-r--r-- 1 root root 87 Jan 16 09:59 mingongge.txt.md5.gz
-rw-r--r-- 1 root root 65 Jan 16 10:19 sort.cut.txt.gz