獨立小橋風滿袖 发表于 2019-3-19 01:52:35

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 kInstalled size: 796 kDownloading packages:zip-3.0-11.el7.x8664.rpm | 260 kB 00:00:03
Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : zip-3.0-11.el7.x8664 1/1 Verifying : zip-3.0-11.el7.x86_64 1/1
Installed:zip.x86_64 0:3.0-11.el7
Complete!

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 检察更具体的资助

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%的空间

4.2 案例2

把指定目次压缩,压缩后生存到当前目次,利用最高压缩率,不表现具体过程

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

4.3 案例3

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

[*][root@zcwyou zip]# zip -dv test.zip 333.txt
实行效果:1>1: updating: 333.txt (deflated 48%)
5. 总结

Linux体系利用zip,请牢记常用的参数,下令行利用起来非常方便。
微信搜刮公众号“智传网优”大概长按以下二维码,然后选择“辨认图中二维码”直接开始自助视频学习,接待留言或与我们讲师直接沟通。

Linux学习QQ群:557371664
页: [1]
查看完整版本: Linux创建zip压缩文件