加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_汕头站长网 (https://www.0754zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Linux创建zip压缩文件

发布时间:2022-10-31 13:17:36 所属栏目:Linux 来源:
导读:  如需学习视频,请查看本头条号简介linux压缩,免费在线观看学习视频

  1. Linux下zip工具简介

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

  2. 安装zip工具

  以CentOS7.5为
  如需学习视频,请查看本头条号简介linux压缩,免费在线观看学习视频
 
  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!
 
  linux安装zip工具
 
  3. zip命令选项
 
  [root@zcwyou ~]# zip --help
  -f 更新压缩文件内容,把更新的文件替换旧文件,并追加新文件
 
  -u 更新压缩文件内容,把更新的文件替换旧文件,不追加新文件
 
  -d 删除压缩包里的文件
 
  linux压缩命令 tar_linux压缩_linux 压缩命令 tar
 
  -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 查看更详细的帮助
 
  linux zip压缩选项
 
  4. 使用zip压缩文件
 
  4.1 案例1
 
  把当前目录下的所有文件和子目录压缩,保存为test.zip
 
  [root@zcwyou zip]# zip -v -r test.zip ./*
  执行过程:
 
  adding: 333.txt (in=315) (out=163) (deflated 48%)
 
  linux压缩命令 tar_linux压缩_linux 压缩命令 tar
 
  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%的空间
 
  linux指定压缩比例压缩zip文件
 
  4.2 案例2
 
  把指定目录压缩,压缩后保存到当前目录,使用最高压缩率,不显示详细过程
 
  [root@zcwyou zip]# zip -q -r -9 etc.zip /etc/*
  linux把指定目录压缩成为zip文件
 
  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,请牢记常用的参数,命令行使用起来非常方便。
 

(编辑:云计算网_汕头站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!