文件/目录操作(7)——zip、gzip、bzip2、tar命令

*.zip
说明:zip对文件和目录都可以进行压缩操作
           zip   file.zip     file1  file2    //将file1file2打包成file.zip
           zip  file.zip     *.jpg           //将所有jpg结尾的文件打包成file.zip
           unzip       file.zip               //解压缩
           unzip  -l   file.zip               //查看压缩文件内容
[root@vm_hosts test]# unzip file.zip 
Archive: file.zip
replace testfile? [y]es, [n]o, [A]ll, [N]one, [r]ename: //解压时若还和原文件冲突,则询问是否替换或重命名 
[root@vm_hosts test]# unzip -l file.zip 
Archive: file.zip
Length Date Time Name
--------- ---------- ----- ----
104857600 07-15-2015 08:13 testfile
--------- -------
104857600 1 file

*.gz
说明:gzip
只能对文件 进行压缩操作
注意:这种方式的压缩和解压都将不再保留原文件或原压缩文件
           gzip    -num //按照#程度打包;num=1—9(1最快压缩比最差,9反之,默认是6)
                   -r        //对目录下所有的子目录所有“文件”递归打包
                   -v       //显示过程
                   -d       //解压缩
           gunzip       //解压缩
           zcat          //查看压缩包文本文件的内容
           gzip < pw > pw.gz      //用输入输出重定向的方法,使得压缩或解压后原文件得以保留
           gunzip <pw.gz >pw
[root@localhost test]# ls
file1 file2
[root@localhost test]# gzip file2 file1
[root@localhost test]# ls
file1.gz file2.gz
[root@localhost test]# gzip -l file1.gz 
compressed uncompressed ratio uncompressed_name
26 0 0.0% file1
[root@localhost test]# ls 
mk1 mk2
[root@localhost test]# gzip mk1
gzip: mk1 is a directory -- ignored
[root@localhost test]# ls mk2
file1 file2
[root@localhost test]# gzip -r mk2
[root@localhost test]# ls mk2
file1.gz file2.gz

*.bz2
说明:基本原理同
*.gz 一样
           bzip2   -num    //压缩
           bzip2   -d         //解压缩
           bzcat


tar命令
      -c:创建 .tar 格式的包文件 -c, --create
      -x:解开.tar格式的包文件 -x, --extract,
      -v:输出详细信息 -v, --verbose
      -f:表示使用归档文件 -f, --file
      -t:列表查看包内的文件     ( tar tf xx.gz   //查看包内内容)
      -p:保持原文件的原来属性
      -P:保持原文件的绝对路径(在创建tar包文件的时候使用,会保留文件的绝对路径,在解压的时候使用,会按照绝对路径去释放压缩包的内容,会替换原来的文件。)(注意,应尽量不使用-P选项)
      -C:解压时指定路径
      --exclude=:指定打包时不包含某个文件
      
--->.tar.gz    tar
zcvf  file.tar.gz    file1 file2  
--->.tar         tar
cvf    file.tar         file1 file2
--->.tar.bz2  tar
jcvf    file.tar.bz2  file1 file2
--->.tar.xz    tar cvf     file.tar        file1 file2  &&   xz -z file.tar.xz
--->.tar.Z     tar Zcvf   file.tar.Z     file1 file2


--->.tar.gz/.tgz  tar   zxvf   xx.tgz/xx.tar.gz
--->.tar/.gz        tar   
xvf    xx.gz/xx.tar
--->.tar.xz         tar   xvf    file.tar.xz 或 xz -d file.tar.xz&&tar xvf file.tar
--->.tar.Z          tar   Zxvf   xx.tar.Z

应用实例:
tar czvf /lianxi/bak123.tar.gz /bak/* --exclude=/bak/{boot,var,etc,jj_diandian.tar.gz}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值