文档的压缩与解压

压缩类别
.gz: gzip压缩工具对应文件
.bz2: bzip2工具
.tar:tar打包程序的文件
.tar.gz: 先由tar打包,再gzip压缩
.tar.bz2:tar打包,再bzip2压缩
.tar.xz:tar打包,再xz压缩

gzip压缩:
-d:解压缩
-#:默认为6,1-9
安装gzip工具:

[root@ligenkelong ~]# yum -y install gzip

解压和压缩文件:

[root@ligenkelong ~]# gzip 2.txt
[root@ligenkelong ~]# ls
2  2.txt.gz  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# gzip -d 2.txt.gz 
[root@ligenkelong ~]# ls
2  2.txt  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# gzip -c 2.txt > /tmp/2.txt.gz
[root@ligenkelong ~]# ls /tmp/
   111       fstab    passwd.sh
2.txt.gz  newdisk  systemd-private
[root@ligenkelong ~]# zcat /tmp/2.txt.gz 

bzip2工具:
安装bzip2:

[root@ligenkelong ~]# yum install -y bzip2

解压与压缩文件:

[root@ligenkelong ~]# bzip2 2.txt 
[root@ligenkelong ~]# ls
2  2.txt.bz2  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# bzip2 -d 2.txt.bz2 
[root@ligenkelong ~]# ls
2  2.txt  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# bzip2 -c 2.txt > /tmp/2.txt.bz2
[root@ligenkelong ~]# ls /tmp
111        fstab    passwd.sh
2.txt.bz2 
  • xz工具用法基本和上面相同

  • zip工具:
    安装

    [root@ligenkelong ~]# yum -y install zip
    [root@ligenkelong ~]# yum install -y unzip
    

压缩和解压:

[root@ligenkelong ~]# zip 2.txt.zip 2.txt 
[root@ligenkelong ~]# ls
2  2.txt  2.txt.zip  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# unzip 2.txt.zip 
Archive:  2.txt.zip
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
 extracting: 2.txt                   
[root@ligenkelong ~]# ls
2  2.txt  2.txt.zip  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# zip -r 2.txt.zip /root/

tar打包
-c:新建打包文件
-t:查看打包文件有哪些文件名
-x:解打包或解压缩
-j:bzip2压缩/解压缩
-z:gzip压缩/解压缩
-v:详细显示
-f:后面加要被处理的文件名

[root@ligenkelong ~]# tar -cvf 2.txt.tar 2.txt 2.txt.zip 
[root@ligenkelong ~]# ls
2  2.txt  2.txt.tar  2.txt.zip  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# tar -xvf 2.txt.tar 
2.txt
2.txt.zip
[root@ligenkelong ~]# ls
2  2.txt  2.txt.tar  2.txt.zip  33.txt  5.txt  anaconda-ks.cfg
[root@ligenkelong ~]# tar -tf 2.txt.tar 
2.txt
2.txt.zip

打包并压缩:

[root@ligenkelong ~]# tar -zcvf ligen.tar.gz 33.txt ./root/
[root@ligenkelong ~]# ls
2  2.txt  2.txt.tar  2.txt.zip  33.txt  5.txt  anaconda-ks.cfg  ligen.tar.gz  root

 [root@ligenkelong ~]# tar -jcvf 22.tar.bz2 anaconda-ks.cfg 5.txt 
 anaconda-ks.cfg
5.txt
[root@ligenkelong ~]# ls
2           2.txt      2.txt.zip  5.txt            ligen.tar.gz
22.tar.bz2  2.txt.tar  33.txt     anaconda-ks.cfg  root

[root@ligenkelong ~]# tar -Jcvf 22.tar.xz anaconda-ks.cfg 5.txt 
anaconda-ks.cfg
5.txt
[root@ligenkelong ~]# ls
2           22.tar.xz  2.txt.tar  33.txt  anaconda-ks.cfg  root
22.tar.bz2  2.txt      2.txt.zip  5.txt   ligen.tar.gz
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值