Linux之zip命令

  • 命令概述

zip 命令用于压缩文件;

  • 命令语法
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  • 命令参数
  • -b

    指定存放文件的目录;

    -d

    删除压缩文件内指定的文件;

    -f

    更新压缩包的文件;

    -m

    将文件压缩并加入压缩文件后,删除原始文件;

    -q

    不显示执行过程;

    -r

    递归处理,将指定目录下的所有文件和子目录一并处理;

    -v

    显示指令执行过程或显示版本信息(默认选项);

    -sf

    显示文件;

  • 命令示例

1、zip test1.zip test1.txt 压缩一个名为test.zip的文件;

[root@localhost test]# zip test1.zip test1.txt   
  adding: test1.txt (deflated 31%)
[root@localhost test]# ll
total 20
-rw-r--r-- 1 root root  13 Jul 16 14:15 test1.txt
-rw-r--r-- 1 root root 177 Jul 17 14:01 test1.zip

 2、zip -r test2.zip test2 -r 表示将指定目录下的所有文件和子目录一并处理;

[root@localhost test]# zip test2.zip test2  --不加r,压缩文件夹
  adding: test2/ (stored 0%)
[root@localhost test]# zip -sf test2.zip    --只对文件夹压缩
Archive contains:
  test2/
Total 1 entries (0 bytes)
[root@localhost test]# zip -r test2.zip test2 --加r,压缩文件夹
updating: test2/ (stored 0%)
  adding: test2/test1.txt (deflated 31%)
[root@localhost test]# zip -sf test2.zip  --指定目录下的所有文件和子目录一并处理
Archive contains:
  test2/
  test2/test1.txt
Total 1 entries (89 bytes)

3、zip -sf test2.zip -sf 表示查看压缩内的文件(zipinfo -1 test2.zip 效果一样);

[root@localhost test]# zip -sf test2.zip  --查看压缩包内的文件
Archive contains:
  test2/
  test2/test1.txt
Total 1 entries (89 bytes)

4、zip -d test2.zip test2/test1.txt -d 表示删除压缩文件内指定的文件(或者当压缩是目录时,指定目录下的文件);

[root@localhost test]# zip -d test2.zip test2/test1.txt --加-d 删除压缩内的文件
deleting: test2/test1.txt

5、zip -q test4.zip test4.txt -q 表示压缩文件或文件夹不显示执行过程;

[root@localhost test]# zip -q test4.zip test4.txt  -- 加-q 不显示执行过程
[root@localhost test]# ll
total 28
-rw-r--r-- 1 root root   0 Jul 16 14:25 test4.txt
-rw-r--r-- 1 root root 168 Jul 17 14:25 test4.zip

6、zip -m test5.zip test5.txt -m 表示将文件压缩并加入压缩文件后,删除原始文件(zip -rm test5.zip test5 对文件压缩后删除需要加 -rm );

[root@localhost test]# ll
-rw-r--r-- 1 root root  50 Jul 16 14:50 test5.txt
[root@localhost test]# zip -m test5.zip test5.txt --加-m 加入压缩文件后,删除原始文件; 
  adding: test5.txt (deflated 4%)
[root@localhost test]# ll
-rw-r--r-- 1 root root 216 Jul 17 14:28 test5.zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值