说明

  unzip命令可以解压zip命令或其他压缩软件压缩的zip格式的文件

格式

  unzip [option] [file]

常用参数
  • -l:不解压显示压缩包内容
  • -d:指定解压的目录
  • -o:解压时不提示是否覆盖文件
  • -v:解压时显示详细信息
示例

1、查看压缩文件(-l)

[root@localhost ~]# unzip -l test.zip 
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  05-14-2018 15:34   test/
       11  05-07-2018 22:45   test/test_01.txt
        0  05-06-2018 07:22   test/test_02.txt
        0  05-06-2018 07:22   test/test_03.txt
        0  05-06-2018 07:22   test/test_04.txt
        0  05-06-2018 07:22   test/test_05.txt
        0  05-06-2018 07:22   test/test_06.txt
        0  05-06-2018 07:22   test/test_07.txt
        0  05-06-2018 07:22   test/test_08.txt
        0  05-06-2018 07:22   test/test_09.txt
        0  05-06-2018 07:22   test/test_10.txt
        0  05-06-2018 07:22   test/test_11.txt
        0  05-06-2018 07:22   test/test_12.txt
        0  05-06-2018 07:24   test/test.txt
---------                     -------
       11                     14 files

2、常规解压文件(这里我们把压缩文件拷贝到/tmp目录下,不然会提示很多信息)

[root@localhost tmp]# unzip test.zip  #第一次解压
Archive:  test.zip
   creating: test/
 extracting: test/test_01.txt        
 extracting: test/test_02.txt        
 extracting: test/test_03.txt        
 extracting: test/test_04.txt        
 extracting: test/test_05.txt        
 extracting: test/test_06.txt        
 extracting: test/test_07.txt        
 extracting: test/test_08.txt        
 extracting: test/test_09.txt        
 extracting: test/test_10.txt        
 extracting: test/test_11.txt        
 extracting: test/test_12.txt        
 extracting: test/test.txt           

 [root@localhost tmp]# unzip test.zip #第二次解压
Archive:  test.zip
replace test/test_01.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A #替换所有
 extracting: test/test_01.txt        
 extracting: test/test_02.txt        
 extracting: test/test_03.txt        
 extracting: test/test_04.txt        
 extracting: test/test_05.txt        
 extracting: test/test_06.txt        
 extracting: test/test_07.txt        
 extracting: test/test_08.txt        
 extracting: test/test_09.txt        
 extracting: test/test_10.txt        
 extracting: test/test_11.txt        
 extracting: test/test_12.txt        
 extracting: test/test.txt

3、指定解压目录

 [root@localhost ~]# unzip -d /tmp/ test.zip  #-d参数使用
Archive:  test.zip
   creating: /tmp/test/
 extracting: /tmp/test/test_01.txt   
 extracting: /tmp/test/test_02.txt   
 extracting: /tmp/test/test_03.txt   
 extracting: /tmp/test/test_04.txt   
 extracting: /tmp/test/test_05.txt   
 extracting: /tmp/test/test_06.txt   
 extracting: /tmp/test/test_07.txt   
 extracting: /tmp/test/test_08.txt   
 extracting: /tmp/test/test_09.txt   
 extracting: /tmp/test/test_10.txt   
 extracting: /tmp/test/test_11.txt   
 extracting: /tmp/test/test_12.txt   
 extracting: /tmp/test/test.txt      
[root@localhost ~]# ll /tmp/test #查看解压后的信息
total 4
-rw-r----x. 1 root root 11 May  7 22:45 test_01.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_02.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_03.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_04.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_05.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_06.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_07.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_08.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_09.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_10.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_11.txt
-rw-r--r--. 1 root root  0 May  6 07:22 test_12.txt
-rw-r--r--. 1 root root  0 May  6 07:24 test.txt