linux zip/unzip命令

unzip命令

主要功能:解压缩zip文件

使用方式:
unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]

将压缩文件file[.zip]中list列表的文件解压到exdir文件夹下,其中解压缩排除xlist列表的文件[夹]

参数说明

  • -Z 转换为ZipInfo mode,必须是第一参数
  • -x 解压缩排除xlist列表的
  • -d 压缩文件解压到exdir文件夹下
    opts
  • -p 将压缩文件显示到屏幕上
  • -f 更新现有的文件
  • -u 与-f参数类似,但是除了更新现有的文件外,也会将压缩文件中 的其他文件解压缩到目录中
  • -v 显示执行过程
  • -l 显示压缩包里含有的文件
  • -t 测试压缩文件是否损坏
  • -z 显示压缩文件的备注信息
  • -T 更新压缩文件修改时间为当前时间
    modifiers
  • -n 解压缩不覆盖原文件
  • -o 强制覆盖原文件
  • -j 不处理压缩文件原有路径
  • -q 执行时不显示信息
  • -M 执行过程用more程序输出
  • -L 将压缩文件中的全部文件名改为小写

例子

1.将压缩文件文件内容用more程序打开【不产生解压的文件】

# unzip -p test.zip | more

[root@MIS-BJ-6-521 test]# unzip -p test.zip | more -1
aaaaaa
sdfdsf
--More--
2.将压缩文件执行过程用more打开【生成解压的文件】

# unzip -M test.zip | more

[root@MIS-BJ-6-521 test]# unzip -M test.zip | more -1
Archive:  test.zip
creating: test/
inflating: test/a                  
--More--
3.查看压缩文件目录

# unzip -l test.zip

 [root@MIS-BJ-6-521 test]# unzip -l test.zip
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  03-29-2016 14:04   test/
       19  03-29-2016 14:03   test/a
       13  03-29-2016 14:03   test/c
        0  03-29-2016 14:03   test/test2/
       13  03-29-2016 14:03   test/test2/b
---------                     -------
       45                     5 files
4.查看压缩文件目录

# unzip test.zip -x test/c

 [root@MIS-BJ-6-521 test]# unzip test.zip -x test/c
Archive:  test.zip
   creating: test/
  inflating: test/a                  
   creating: test/test2/
  inflating: test/test2/b 

zip命令

主要功能:压缩zip文件

使用方式:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]

将压缩文件file[.zip]中list列表的文件解压到exdir文件夹下,其中解排除-x list列表的压缩文件

参数说明

  • -f 只是更新文件
  • -d 删除指定的文件
  • -r 递归处理
  • -f 只是更新文件
  • -o 以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同。
  • -q 不显示执行过程
  • -c 为每个被压缩的文件加上注释
  • -x 剔除符合条件的文件
  • -F 修复压缩文件
  • -T 检查压缩文件正确无误
  • -u 更新和添加新文件
  • -m 将文件添加到压缩文件,并删除原文件
  • -j 只保存文件不保存目录
  • -l 压缩文件时,把LF字符 置换成LF+CR字符(linux换行->win换行)
  • -ll 压缩文件时,把LF+CR字符 置换成LF字符(win换行->linux换行)
  • -z 替压缩文件加上注释
  • -i 只包含符合条件的文件
  • -n不压缩具有特定字尾字符串(文件扩展名)的文件(但是会存储到压缩文件里面)
  • -b 指定暂时存放文件的目录
  • -t 把list里面修改时间晚于指定时间点的文件,放到压缩文件里面(网上有的地方错写成压缩文件修改为此时间)

例子

1.排除test/c文件,打包test文件夹为test.zip

# zip -r test.zip test -x test/c

[root@MIS-BJ-6-521 test]# zip -r  test.zip test  -x test/c
  adding: test/ (stored 0%)
  adding: test/a (deflated 5%)
  adding: test/test2/ (stored 0%)
  adding: test/test2/b (deflated 23%)
--More--
2.修改test/a文件,更新1打包的文件夹文件,并不会添加test/c文件

# zip -rf test.zip test

[root@MIS-BJ-6-521 test]# zip -rf test.zip test 
freshening: test/ (stored 0%)
freshening: test/a (stored 0%)
3.修改test/a文件,更新并添加1打包的文件夹文件,会添加test/c文件并更新test/a

# # zip -ru test.zip test

[root@MIS-BJ-6-521 test]# zip -ru test.zip test 
updating: test/ (stored 0%)
updating: test/a (stored 0%)
  adding: test/c (deflated 23%)
4.不压缩扩展名为.txt 的文件,此时处理a.txt直接将文件存储到压缩文件,并未进行压缩

# # zip -r -n .txt test.zip test

[root@MIS-BJ-6-521 test]# zip -r -n .txt test.zip test
  adding: test/ (stored 0%)
  adding: test/c (deflated 23%)
  adding: test/test2/ (stored 0%)
  adding: test/test2/b (deflated 23%)
  adding: test/a.a (stored 0%)

test1.zip 是未压缩a.txt test.zip是压缩了a.txt

-rw-r--r--. 1 root root     1136 Mar 29 16:15 test1.zip
-rw-r--r--. 1 root root      796 Mar 29 16:14 test.zip
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值