shell命令 - zip/unzip

用途

压缩/解压缩

语法及描述

zip

zip [-dDqrS] [-b path] [zipfile [file ...]]
  • -d : 从 压缩文件内删除指定的文件
  • -D : 压 缩文件内不建立目录名称
  • -q : 不显 示指令执行过程
  • -r : 递 归处理,将指定目录下的所有文件和子目录一并处理
  • -S : 包 含系统和隐藏文件
  • -<压缩效率> 压 缩效率是一个介于1-9的 数值
  • -b : 创建zip文件临时目录

unzip

unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] [-d exdir]
  • -j : 目录结构不重新创建
  • \file[.zip]:待解压的包
  • [file(s) …]:要解压的文件,默认解压全部文件
  • \ -d : 解压的输出目录,默认当前目录

举例

压缩目录

~/Downloads/test1$ tree
.
└── test
    ├── a
    ├── b
    └── dir
        └── c

2 directories, 3 files
~/Downloads/test1$ 
~/Downloads/test1$ zip -r test test
  adding: test/ (stored 0%)
  adding: test/a (stored 0%)
  adding: test/dir/ (stored 0%)
  adding: test/dir/c (stored 0%)
  adding: test/b (stored 0%)
~/Downloads/test1$ ls
test  test.zip
  • 压缩文件
~/Downloads/test0$ ls
a  b
~/Downloads/test0$ zip ab a b
  adding: a (stored 0%)
  adding: b (stored 0%)
~/Downloads/test0$ ls
a  ab.zip  b
  • 解压文件
~/Downloads/test1$ unzip test.zip -d out
Archive:  test.zip
   creating: out/test/
 extracting: out/test/a              
   creating: out/test/dir/
 extracting: out/test/dir/c          
 extracting: out/test/b              
~/Downloads/test1$ 
~/Downloads/test1$ cd out/
~/Downloads/test1/out$ ls
test
~/Downloads/test1/out$ tree
.
└── test
    ├── a
    ├── b
    └── dir
        └── c

2 directories, 3 files
  • 解压某些文件
~/Downloads/test1$ unzip test.zip "test/dir/c" -d out
Archive:  test.zip
 extracting: out/test/dir/c          
~/Downloads/test1$ cd out/
~/Downloads/test1/out$ tree
.
└── test
    └── dir
        └── c

2 directories, 1 file
  • 解压某些文件,不重新创建路径
~/Downloads/test1$ unzip -j test.zip "test/dir/c" -d out
Archive:  test.zip
 extracting: out/c                   
~/Downloads/test1$ cd out/
~/Downloads/test1/out$ tree
.
└── c

0 directories, 1 file
  • 解压某些文件到当前目录
~/Downloads/test1$ unzip -j test.zip "test/dir/c"
Archive:  test.zip
 extracting: c                       
~/Downloads/test1$ 
3 directories, 5 files
~/Downloads/test1$ ls
c  out  test  test.zip
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值