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

你可能感兴趣的:(shell)