Linux命令(64)之unzip

linux命令之unzip

1.unzip介绍

linux命令unzip是用来解压缩文件名后缀为.zip的文件。

unzip命令yum(前提:yum源存在且可用)安装命令:

yum install unzip -y

yum源配置方式:

Linux常规基础配置_小黑要上天的博客-CSDN博客

2.unzip用法

unzip [参数] filename.zip

unzip常用参数
参数说明
-q静默解压缩
-d解压缩zip文件到指定目录
-P <passwd>解压缩有密码的 ZIP 文件
-x排除指定文件解压缩
-o覆盖现有文件解压缩
-n跳过已存在文件的提取
-l列出zip文件的内容
-t测试归档数据的正确性

3.实例

3.1.列出ztj.zip文件的内容

命令:

unzip -l ztj.zip

[root@rhel77 ~]# unzip -l ztj.zip
Archive:  ztj.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  07-20-2023 08:34   ztj/
      173  02-13-2023 19:02   ztj/root.sh
      179  02-13-2023 19:02   ztj/root-1.sh
        0  05-15-2023 20:46   ztj/test/
     3218  05-15-2023 20:46   ztj/test/passwd
        0  07-20-2023 08:33   ztj/1.txt
        0  07-20-2023 08:34   ztj/2.txt
        0  07-20-2023 08:34   ztj/3.txt
        0  07-20-2023 08:34   ztj/4.txt
        0  07-20-2023 08:34   ztj/5.txt
        0  07-20-2023 08:34   ztj/6.txt
---------                     -------
     3570                     11 files
[root@rhel77 ~]# 

3.2.解压ztj.zip至当前目录

命令:

unzip ztj.zip

[root@rhel77 ~]# unzip ztj.zip 
Archive:  ztj.zip
   creating: ztj/
  inflating: ztj/root.sh             
  inflating: ztj/root-1.sh           
   creating: ztj/test/
  inflating: ztj/test/passwd         
 extracting: ztj/1.txt               
 extracting: ztj/2.txt               
 extracting: ztj/3.txt               
 extracting: ztj/4.txt               
 extracting: ztj/5.txt               
 extracting: ztj/6.txt               
[root@rhel77 ~]# ls -ld ztj
drwxrwxrwx 3 root root 128 Jul 20 08:34 ztj
[root@rhel77 ~]# 

3.3.静默解压缩ztj.zip文件

命令:

unzip -q ztj.zip

[root@rhel77 ~]# unzip -q ztj.zip 
[root@rhel77 ~]# ls -ld ztj
drwxrwxrwx 3 root root 128 Jul 20 08:34 ztj
[root@rhel77 ~]# 

3.4.解压ztj.zip文件到test目录

命令:

unzip ztj.zip -d test

[root@rhel77 ~]# unzip ztj.zip -d test
Archive:  ztj.zip
   creating: test/ztj/
  inflating: test/ztj/root.sh        
  inflating: test/ztj/root-1.sh      
   creating: test/ztj/test/
  inflating: test/ztj/test/passwd    
 extracting: test/ztj/1.txt          
 extracting: test/ztj/2.txt          
 extracting: test/ztj/3.txt          
 extracting: test/ztj/4.txt          
 extracting: test/ztj/5.txt          
 extracting: test/ztj/6.txt          
[root@rhel77 ~]# cd test
[root@rhel77 test]# ls -ld ztj
drwxrwxrwx 3 root root 128 Jul 20 08:34 ztj
[root@rhel77 test]# 

3.5.解压带有密码的z.zip文件

命令:

unzip -P <passwd> z.zip

[root@rhel77 ~]# unzip -P ztj z.zip
Archive:  z.zip
   creating: ztj/
   creating: ztj/test/
  inflating: ztj/test/passwd         
  inflating: ztj/root.sh             
  inflating: ztj/root-1.sh           
 extracting: ztj/1.txt               
 extracting: ztj/2.txt               
 extracting: ztj/3.txt               
 extracting: ztj/4.txt               
 extracting: ztj/5.txt               
 extracting: ztj/6.txt               
[root@rhel77 ~]# ls -ld ztj
drwxrwxrwx 3 root root 128 Jul 20 08:47 ztj
[root@rhel77 ~]# 

3.6.排查指定文件解压缩ztj.zip

命令:

unzip ztj.zip -x "file"

[root@rhel77 ~]# unzip ztj.zip -x "*.txt"
Archive:  ztj.zip
   creating: ztj/
  inflating: ztj/root.sh             
  inflating: ztj/root-1.sh           
   creating: ztj/test/
  inflating: ztj/test/passwd         
[root@rhel77 ~]# cd ztj
[root@rhel77 ztj]# ls
root-1.sh  root.sh  test
[root@rhel77 ztj]# 

3.7.覆盖现有文件解压缩ztj.zip

命令:

unzip -o ztj.zip

[root@rhel77 ~]# unzip -o ztj.zip 
Archive:  ztj.zip
   creating: ztj/
  inflating: ztj/root.sh             
  inflating: ztj/root-1.sh           
   creating: ztj/test/
  inflating: ztj/test/passwd         
 extracting: ztj/1.txt               
 extracting: ztj/2.txt               
 extracting: ztj/3.txt               
 extracting: ztj/4.txt               
 extracting: ztj/5.txt               
 extracting: ztj/6.txt               
[root@rhel77 ~]# 

3.8.跳过已存在文件的提取ztj.zip

命令:

unzip -n ztj.zip

[root@rhel77 ~]# unzip -n ztj.zip 
Archive:  ztj.zip
[root@rhel77 ~]# 

3.9.测试ztj.zip文件的正确性

命令:

unzip -t ztj.zip

[root@rhel77 ~]# unzip -t ztj.zip 
Archive:  ztj.zip
    testing: ztj/                     OK
    testing: ztj/root.sh              OK
    testing: ztj/root-1.sh            OK
    testing: ztj/test/                OK
    testing: ztj/test/passwd          OK
    testing: ztj/1.txt                OK
    testing: ztj/2.txt                OK
    testing: ztj/3.txt                OK
    testing: ztj/4.txt                OK
    testing: ztj/5.txt                OK
    testing: ztj/6.txt                OK
No errors detected in compressed data of ztj.zip.
[root@rhel77 ~]# 

以上就是linux命令unzip的用法,希望对大家有所帮助!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值