前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >6.5 zip压缩工具

6.5 zip压缩工具

作者头像
运维小白
发布2018-02-06 10:48:04
1.1K0
发布2018-02-06 10:48:04
举报
文章被收录于专栏:运维小白运维小白

zip目录概要

  • zip支持压缩目录
  • zip 1.txt.zip 1.txt 压缩文件
  • zip -r 123.zip 123/ 压缩文件到指定目录下
  • unzip 1.txt.zip 解压文件
  • unzip 123.zip -d /root/456/ 解压文件到制定目录
  • unzip -l 123.zip 查看压缩文件列表

zip压缩文件或目录

  • 在linux和windows中都有一个zip压缩工具,但是linux下不支持解压windos下的rar文件(默认不支持,需要安装工具才可以)
  • 安装zip包——>yum install -y zip
代码语言:javascript
复制
[root@hf-01 d6z]# mkdir -p /tmp/hf/han/hanfeng
[root@hf-01 d6z]# cd /tmp/hf
[root@hf-01 hf]# touch 1.txt
[root@hf-01 hf]# touch /tmp/hf/han/wu.txt
[root@hf-01 hf]# touch /tmp/hf/han/hanfeng/66.txt
[root@hf-01 hf]# cd /tmp/d6z
[root@hf-01 d6z]# ls /tmp
12.txt  1.txt  2.txt.bz2  d6z  ha.txt.xz  hf  mysql.sock  vim.txt
[root@hf-01 d6z]# cp -r /tmp/hf .
[root@hf-01 d6z]# ls
1.txt  4.txt  5.txt  8.xt  hf
[root@hf-01 d6z]# tree hf/
hf/
├── 1.txt
└── han
    ├── hanfeng
    │   └── 66.txt
    └── wu.txt

2 directories, 3 files
[root@hf-01 d6z]# cp 1.txt hf/han/hanfeng/
[root@hf-01 d6z]# du -sh hf/
1.5M	hf/

zip压缩文件

  • zip 1.txt.zip 1.txt 压缩文件
代码语言:javascript
复制
[root@hf-01 d6z]# zip 1.txt.zip 1.txt
  adding: 1.txt (deflated 74%)
[root@hf-01 d6z]# du -sh 1.txt.zip
388K	1.txt.zip
[root@hf-01 d6z]# ls
1.txt  1.txt.zip  4.txt  5.txt  8.xt  hf

zip压缩目录

  • zip -r hafe.zip 8.txt hf 压缩文件和目录
代码语言:javascript
复制
[root@hf-01 d6z]# zip -r hafe.zip 8.txt hf
	zip warning: name not matched: 8.txt
  adding: hf/ (stored 0%)
  adding: hf/han/ (stored 0%)
  adding: hf/han/hanfeng/ (stored 0%)
  adding: hf/han/hanfeng/66.txt (stored 0%)
  adding: hf/han/hanfeng/1.txt (deflated 74%)
  adding: hf/han/wu.txt (stored 0%)
  adding: hf/1.txt (stored 0%)
[root@hf-01 d6z]# ls 
1.txt 8.txt hf hafe.zip

zip压缩文件后不删除之前的文件

zip解压文件

  • 解压zip包——>yum install -y unzip
  • unzip yasuo.zip 解压文件
    • 解压文件的时候,会提示 “是否覆盖”、“是否替换”等, A 表示全部解压(因为压缩的时候不会删除源文件)
代码语言:javascript
复制
[root@localhost d6z]# unzip yasuo.zip
Archive:  yasuo.zip
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: 2.txt                   
 extracting: hf/han/hanfeng/66.txt   
  inflating: hf/han/hanfeng/1.txt    
 extracting: hf/han/wu.txt           
 extracting: hf/1.txt                
 extracting: hf/11.txt               
[root@localhost d6z]# 

zip解压文件到指定目录

  • unzip 1.txt.zip -d lala/ 解压文件到指定目录下(若不指定目录,就会在当前目录下)
代码语言:javascript
复制
[root@localhost d6z]# mkdir lala
[root@localhost d6z]# unzip 1.txt.zip -d lala/
Archive:  1.txt.zip
  inflating: /lala/1.txt 
  • zip解压文件不能指定文件名,压缩的时候是什么文件名,解压的时候还是这个文件名
  • zip的压缩文件,是无法查看的

查看zip压缩包的文件列表

  • unzip -l yasuo.zip 查看压缩文件列表
代码语言:javascript
复制
[root@localhost d6z]# unzip -l yasuo.zip
Archive:  yasuo.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
  1283485  11-09-2017 16:02   2.txt
        0  11-10-2017 10:40   hf/
        0  11-10-2017 10:41   hf/han/
        0  11-10-2017 10:45   hf/han/hanfeng/
        0  11-10-2017 10:41   hf/han/hanfeng/66.txt
  1283485  11-10-2017 10:45   hf/han/hanfeng/1.txt
        0  11-10-2017 10:41   hf/han/wu.txt
        0  11-10-2017 10:40   hf/1.txt
        0  11-10-2017 10:40   hf/11.txt
---------                     -------
  2566970                     9 files
[root@localhost d6z]# 

总结

  • gzip、bzip2、xz这三种压缩工具是可以指定解压文件的目录和名称,而zip只可以指定目录,却不能指定解压文件名称
  • zip压缩工具可以压缩文件和目录,但gzip、bzip2、xz这三种却不可以压缩目录
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • zip目录概要
  • zip压缩文件或目录
    • zip压缩文件
      • zip压缩目录
      • zip解压文件
      • zip解压文件到指定目录
      • 查看zip压缩包的文件列表
      • 总结
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档