每天回顾linux命令(unzip)

来源:互联网 发布:时代网络大厦 联想电脑 编辑:程序博客网 时间:2024/06/14 00:30

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

语法

unzip (选项) (参数)

选项
-c:将解压的结果显示到屏幕上,并对字符做适当的转换;

root@35d388cf883b:/home/wzm/testgzip/zip# cat testzip123abcroot@35d388cf883b:/home/wzm/testgzip/zip# zip test.zip testzip  adding: testzip (stored 0%)root@35d388cf883b:/home/wzm/testgzip/zip# unzip -c test.zipArchive:  test.zip extracting: testzip123abcroot@35d388cf883b:/home/wzm/testgzip/zip#

-f:更新现有的文件。
-l:显示压缩文件内所包含的文件。

root@35d388cf883b:/home/wzm/testgzip/ret# unzip -l test.zipArchive:  test.zip  Length      Date    Time    Name---------  ---------- -----   ----        0  2017-11-21 03:19   zip/    57764  2017-11-20 01:26   zip/redis.conf        0  2017-11-21 02:25   zip/addfile.txt        8  2017-11-21 02:11   zip/.testzip---------                     -------    57772                     4 filesroot@35d388cf883b:/home/wzm/testgzip/ret#

-p:和-c参数类似,会将解压的结果显示到屏幕上,但不会执行任何的转换;
-t:检查压缩文件是否正确。

root@35d388cf883b:/home/wzm/testgzip/ret# unzip -t test.zipArchive:  test.zip    testing: zip/                     OK    testing: zip/redis.conf           OK    testing: zip/addfile.txt          OK    testing: zip/.testzip             OKNo errors detected in compressed data of test.zip.root@35d388cf883b:/home/wzm/testgzip/ret#

-u:和-f参数类似,但是除了更新现有的文件外,也会将压缩文件中的其他文件压缩到目录中;

root@35d388cf883b:/home/wzm/testgzip/ret# unzip -u test.zipArchive:  test.zip   creating: zip/  inflating: zip/redis.conf extracting: zip/addfile.txt extracting: zip/.testziproot@35d388cf883b:/home/wzm/testgzip/ret# lstest.zip  ziproot@35d388cf883b:/home/wzm/testgzip/ret#

-v:执行时显示详细的信息

root@35d388cf883b:/home/wzm/testgzip/ret# unzip -v test.zipArchive:  test.zip Length   Method    Size  Cmpr    Date    Time   CRC-32   Name--------  ------  ------- ---- ---------- ----- --------  ----       0  Stored        0   0% 2017-11-21 03:19 00000000  zip/   57764  Defl:X    19974  65% 2017-11-20 01:26 6a80b091  zip/redis.conf       0  Stored        0   0% 2017-11-21 02:25 00000000  zip/addfile.txt       8  Stored        8   0% 2017-11-21 02:11 bd2b0b01  zip/.testzip--------          -------  ---                            -------   57772            19982  65%                            4 filesroot@35d388cf883b:/home/wzm/testgzip/ret#

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

root@35d388cf883b:/home/wzm/testgzip/ret# unzip -z test.zipArchive:  test.ziproot@35d388cf883b:/home/wzm/testgzip/ret#

-a:对文本进行必要的字符转换
-b:不要对文本进行必要的字符转换
-C:压缩文件的的文件名称区分大小写
-j:不处理压缩文件中原有的目录路径
-L:将压缩文件中的全部文件名改为小写
-n:解压缩时不覆盖原有的文件;
-o:不必先询问用户,覆盖原有文件

root@35d388cf883b:/home/wzm/testgzip/ret# unzip test.zipArchive:  test.zipreplace zip/Testzip? [y]es, [n]o, [A]ll, [N]one, [r]ename:root@35d388cf883b:/home/wzm/testgzip/ret# unzip -o test.zip                                                             Archive:  test.zip                                                                                                       extracting: zip/Testzip                                                                                                  inflating: zip/redis.conf                                                                                              extracting: zip/addfile.txt                                                                                            root@35d388cf883b:/home/wzm/testgzip/ret# 

-p密码:使用zip的密码选项
-q:执行时不显示任何信息

root@35d388cf883b:/home/wzm/testgzip/ret# rm zip -rroot@35d388cf883b:/home/wzm/testgzip/ret# unzip -q test.ziproot@35d388cf883b:/home/wzm/testgzip/ret# rm zip -rroot@35d388cf883b:/home/wzm/testgzip/ret# unzip test.zipArchive:  test.zip   creating: zip/ extracting: zip/Testzip  inflating: zip/redis.conf extracting: zip/addfile.txtroot@35d388cf883b:/home/wzm/testgzip/ret#

-s:将文件名中的空白字符转换为底线字符
-X:解压的同事回存文件原来的UID/GID
-d 目录:指定文件压缩后所要存储的目录
-x 文件:指定不要处理.zip压缩文件中的哪些文件。