51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

压缩解压之zip|unzip|tar

目录

zip {#zip}

zip ana.zip anaconda-ks.cfg # 压缩 
zip test.zip install.log install.log.syslog # 同时压缩多个文件到test.zip压缩包中 
zip -r dir1.zip dir1 # 压缩目录

unzip {#unzip}

unzip test.zip #把文件解压到当前目录下
unzip -d /temp test.zip #如果要把文件解压到指定的目录下,需要用到-d参数。
#解压的时候,有时候不想覆盖已经存在的文件,那么可以加上-n参数
unzip -n test.zip 
unzip -n -d /temp test.zip
unzip -l test.zip #只看一下zip压缩包中包含哪些文件,不进行解压缩
unzip -v test.zip #查看显示的文件列表还包含压缩比率
unzip -t test.zip #检查zip文件是否损坏
#将压缩文件test.zip在指定目录tmp下解压缩,如果已有相同的文件存在,要求unzip命令覆盖原先的文件
unzip -o test.zip -d /tmp/

Tar {#Tar}

tar -zcvf test.tar.gz test #压缩当前目录下文件夹/文件test到test.tar.gz
tar -zxvf file.tar.gz #解压缩当前目录下的file.tar.gz到file
tar -tf test.tar.gz #在不解压的情况下查看压缩包的内容

参数详解 {#i}

五个命令中必选一个 {#i-2}

  • -c: 建立压缩档案
  • -x:解压
  • -t:查看内容
  • -r:向压缩归档文件末尾追加文件
  • -u:更新原压缩包中的文件

这几个参数是可选的 {#i-3}

  • -z:有gzip属性的
  • -j:有bz2属性的
  • -Z:有compress属性的
  • -v:显示所有过程
  • -O:将文件解开到标准输出

-f必选参数 {#-f}

-f: 使用档案名字,这个参数是最后一个参数,后面只能接档案名。


赞(2)
未经允许不得转载:工具盒子 » 压缩解压之zip|unzip|tar