linux保存压缩程序输出,Linux压缩zip文件

1. Linux下zip工具简介

Linux上使用命令行版的zip压缩工具创建zip压缩文件。

2. 安装zip工具

以CentOS7.5为例,默认情况下,最小化安装并没有包括zip套件。

[root@zcwyou ~]# yum -y install zip

输出以下信息表明安装成功:

Installing:

zip x86_64 3.0-11.el7 base 260 k

Transaction Summary

Install 1 Package

Total download size: 260 k

Installed size: 796 k

Downloading packages:

zip-3.0-11.el7.x86_64.rpm | 260 kB 00:00:03

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : zip-3.0-11.el7.x86_64 1/1

Verifying : zip-3.0-11.el7.x86_64 1/1

Installed:

zip.x86_64 0:3.0-11.el7

Complete!

abfb4d2dfc694cbadf853fd5dced8350.png

3. zip命令选项

[root@zcwyou ~]# zip --help

-f 更新压缩文件内容,把更新的文件替换旧文件,并追加新文件

-u 更新压缩文件内容,把更新的文件替换旧文件,不追加新文件

-d 删除压缩包里的文件

-m 把文件加入到压缩包内,并删除源文件

-r 操作递归到子目录

-j 只保留文件和内容,不存放任何目录。

-0 压缩率,即只保存不压缩。

-l 把LF字符转换成LF+CR字符。

-1 快速压缩

-9 最好的压缩率

-q 静默模式

-v 输出打印执行的详细信息

-c 添加注释

-z 添加压缩文件注释

-@ 从标准输出读取文字

-o 以最新的文件更新时间为准,更新其他文件

-x 排除某些文件名

-i 仅仅包括指定文件

-F 修复压缩文件

-D 不添加目录

-A 调整自解压的exe文档

-J 不记录zip文件前缀

-T 校验压缩文件的完整性

-X 不保存额外的文件属性。

-y 保存链接,不保存指向文件

-e 加密

-n 不压缩具有特定字尾字符串的文件。

-h2 查看更详细的帮助

eab5663f30a09c65a1cd9fd171548a1c.png

4. 使用zip压缩文件

4.1 案例1

把当前目录下的所有文件和子目录压缩,保存为test.zip

[root@zcwyou zip]# zip -v -r test.zip ./*

执行过程:

adding: 333.txt (in=315) (out=163) (deflated 48%)

adding: abc.txt (in=9) (out=9) (stored 0%)

adding: cisco1.txt (in=173) (out=120) (deflated 31%)

adding: cisco2.txt (in=179) (out=121) (deflated 32%)

adding: compress.txt (in=0) (out=0) (stored 0%)

adding: cp1.txt (in=0) (out=0) (stored 0%)

adding: cp2.txt (in=0) (out=0) (stored 0%)

adding: cut2.txt (in=57) (out=40) (deflated 30%)

adding: cut.txt (in=50) (out=50) (stored 0%)

adding: diff1.txt (in=9) (out=9) (stored 0%)

adding: diff2.txt (in=18) (out=18) (stored 0%)

adding: dir123/ (in=0) (out=0) (stored 0%)

adding: hard123.txt (in=0) (out=0) (stored 0%)

adding: hard.txt (in=0) (out=0) (stored 0%)

adding: linux123.txt (in=0) (out=0) (stored 0%)

adding: soft.txt (in=0) (out=0) (stored 0%)

adding: test.txt (in=10) (out=10) (stored 0%)

total bytes=820, compressed=540 -> 34% savings

表示节省了34%的空间

ac3c2358e263bf7134a3de34d6116ce5.png

4.2 案例2

把指定目录压缩,压缩后保存到当前目录,使用最高压缩率,不显示详细过程

[root@zcwyou zip]# zip -q -r -9 etc.zip /etc/*

5c561827ed076bf3d6804eb00e69ef32.png

4.3 案例3

从压缩包test.zip里删除333.txt

[root@zcwyou zip]# zip -dv test.zip 333.txt

执行结果:

1>1: updating: 333.txt (deflated 48%)

总结:Linux系统使用zip,请牢记常用的参数,命令行使用起来非常方便。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值