zip压缩工具

来源:互联网 发布:c语言switch case语句 编辑:程序博客网 时间:2024/05/29 11:16

安装zip压缩工具

# yum install -y zip

安装unzip<解压缩>

# yum install -y unzip
  1. 命令语法
    zip(选项)(参数)

  2. 命令描述
    zip命令可以用来解压缩文件,或者对文件进行打包操作,它可以压缩目录或文件,压缩目录时,需要指定目录下的文件。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。

  3. 命令选项
    -r 压缩目录时,需要有-r选项
    -d 解压缩时指定压缩后的文件或目录存放位置。

  4. 命令示例

    • 使用zip压缩,并查看压缩后的文件大小
[root@localhost d6z]# zip 2.txt.zip 2.txt     //压缩2.txt,并保存原文件,在同一目录下。  adding: 2.txt (deflated 74%)[root@localhost d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  dl[root@localhost d6z]# du -sh 2.txt.zip        //查看压缩文件大小332K    2.txt.zip[root@localhost d6z]# zip -r dl.zip dl     //压缩dl目录,并保存原目录,在同一目录下。  adding: 3.txt (deflated 74%)  adding: dl/ (stored 0%)  adding: dl/passwd (deflated 60%)  adding: dl/dd/ (stored 0%)  adding: dl/dd/passwd (deflated 60%)  adding: dl/dddl/ (stored 0%)  adding: dl/dddl/passwd (deflated 60%)  adding: dl/dl (deflated 74%)[root@localhost d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  dl  dl.zip[root@localhost d6z]# du -sh dl.zip    //查看压缩后的文件大小。664K    dl.zip
  • 解压缩zip
[root@localhost d6z]# unzip dl.zip        //解压缩dl.zipArchive:  dl.zipreplace 3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: Y           //是否覆盖原目录  inflating: 3.txt                                replace dl/dd/passwd? [y]es, [n]o, [A]ll, [N]one, [r]ename: A    //全部覆盖  inflating: dl/dd/passwd              inflating: dl/dddl/passwd            inflating: dl/dl                   [root@localhost d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  dl  dl.zip[root@localhost d6z]# du -sh dl1.3M    dl
[root@localhost d6z]# mkdir test    //创建test目录[root@localhost d6z]# ls1.txt.bz2  2.txt  2.txt.zip  3.txt  4.txt  dl  dl.zip  test[root@localhost d6z]# unzip 2.txt.zip -d test    //解压缩到test目录下,-d指定目录Archive:  2.txt.zip  inflating: test/2.txt       

注意:解压缩时不能更改,解压缩后的文件或目录名。


  • 查看压缩后的文件目录列表
[root@localhost d6z]# unzip -l dl.zip        //查看压缩文件的目录列表。不能直接查看文件内容。Archive:  dl.zip  Length      Date    Time    Name---------  ---------- -----   ----  1283485  11-10-2017 10:21   3.txt        0  11-10-2017 20:52   dl/     1254  11-10-2017 20:51   dl/passwd        0  11-10-2017 20:51   dl/dd/     1254  11-10-2017 20:51   dl/dd/passwd        0  11-10-2017 20:51   dl/dddl/     1254  11-10-2017 20:51   dl/dddl/passwd  1283485  11-10-2017 20:52   dl/dl---------                     -------  2570732                     8 files
原创粉丝点击