压缩类别
.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