【Linux】一步一步学Linux——unzip命令(68)

00. 目录

01. 命令概述

unzip命令用于解压缩由zip命令压缩的“.zip”压缩包。

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

02. 命令格式

unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] [-x xfile(s) ...] [-d exdir]

03. 常用选项

-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;
-d<目录>:指定文件解压缩后所要存储的目录;
-x<文件>:指定不要处理.zip压缩文件中的哪些文件;
-Z:unzip-Z等于执行zipinfo指令。

04. 参考示例

4.1 将压缩文件解压缩至当前目录下

[deng@localhost test]$ unzip a
Archive:  a.zip
 extracting: a                       
[deng@localhost test]$ ls
a  a.zip  b  b.zip  c  d  e
[deng@localhost test]$ 

4.2 解压缩时不覆盖原有文件

[deng@localhost test]$ ls
a  a.zip  b  b.zip  c  d  e
[deng@localhost test]$ unzip -n a.zip 
Archive:  a.zip
[deng@localhost test]$ 

4.3 解压缩时覆盖原有文件

不必询问用户,unzip 执行后覆盖原有文件

[deng@localhost test]$ unzip -o a.zip 
Archive:  a.zip
 extracting: a                       
[deng@localhost test]$ 

4.4 将压缩文件解压缩至指定目录下

[deng@localhost test]$ mkdir dir
[deng@localhost test]$ unzip -n a.zip -d dir/
Archive:  a.zip
 extracting: dir/a                   
[deng@localhost test]$ tree dir
dir
└── a

0 directories, 1 file
[deng@localhost test]$ 

4.5 查看压缩文件目录(不解压)

[deng@localhost test]$ unzip -v a.zip 
Archive:  a.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 07-24-2019 21:15 00000000  a
--------          -------  ---                            -------
       0                0   0%                            1 file
[deng@localhost test]$ 

4.6 显示注释内容

[deng@localhost test]$ zip -z aa.zip a
  adding: a (stored 0%)
enter new zip file comment (end with .):
神马程序员.  
[deng@localhost test]$ unzip -z aa.zip
Archive:  aa.zip
神马程序员
[deng@localhost test]$ 

4.7 显示文件中内容(不解压)

[deng@localhost test]$ unzip -l aa.zip 
Archive:  aa.zip
神马程序员

  Length      Date    Time    Name
---------  ---------- -----   ----
        0  07-24-2019 21:15   a
---------                     -------
        0                     1 file
[deng@localhost test]$ 

4.8 用一个zipinfo命令来显示详细信息

[deng@localhost test]$ zipinfo a.zip 
Archive:  a.zip
Zip file size: 152 bytes, number of entries: 1
-rw-rw-r--  3.0 unx        0 bx stor 19-Jul-24 21:15 a
1 file, 0 bytes uncompressed, 0 bytes compressed:  0.0%
[deng@localhost test]$ 

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值