6.1 压缩打包介绍
Windows常见压缩文件格式: .rar .zip .7z
Linux常见压缩文件格式: .zip, .gz, .bz2, .xz, .tar.gz, .tar.bz2, .tar.xz
其实linux系统中的后缀名要不要无所谓,但是对于压缩文件来讲必须要带上.这是为了判断压缩文件是由哪种压缩工具所压缩,而后才能去正确的解压缩这个文件.
压缩的好处是不仅能节省磁盘空间,而且在进行网络传输的时候还能节省网络带宽,减少网络传输时间.
6.2 gzip压缩工具
语法:
gzip [-d#] filename 其中#为1-9的数字
-d : 解压缩时使用
-# : 压缩等级,1压缩最差,9压缩最好,6为默认
gzip -c 1.txt > /tmp/1.txt.gz #将1.txt压缩并将压缩后文件放到/tpm下命名为1.txt.gz,并保留原文件
gunzip 1.txt.gz #将1.txt.gz解压缩
注: gzip不能压缩目录
zcat 1.txt.gz #查看1.txt.gz文件内容
file filenam3 #查看文件的类型
<------------------------------------------------------------------------------------------------------------------------>
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# gzip 1.txt
[root@kh-01 ~]# ls
1.txt.gz anaconda-ks.cfg test test2
[root@kh-01 ~]# gzip -d 1.txt.gz
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# gzip -c 1.txt > test2/2.txt.gz
[root@kh-01 ~]# ls test2/
2.txt.gz test.txt
[root@kh-01 ~]# zcat test2/2.txt.gz
This is a test file.`rnd this is the first time to use "vim".
It is easy to use "vim".
I like to using it,do you like it?
[root@kh-01 ~]# gunzip test2/2.txt.gz
[root@kh-01 ~]# ls test2/
2.txt test.txt
[root@kh-01 ~]# gzip test2/
gzip: test2/ is a directory -- ignored #不能压缩目录
[root@kh-01 ~]#
[root@kh-01 ~]# ls
1.txt.gz anaconda-ks.cfg test test2
[root@kh-01 ~]# file 1.txt.gz
1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Fri Jan 5 16:35:22 2018
[root@kh-01 ~]#
<------------------------------------------------------------------------------------------------------------------------>
6.3 bzip2压缩工具
bzip2与gzip用法相似,bzip2压缩率相对更高些.
语法:
bzip2 [-dz] filename
-d : 解压缩
-z : 压缩,可加可不加,都可以压缩文件
bzip2 -c 1.txt > /tmp/1.txt.bz2 #将1.txt压缩并将压缩后文件放到/tpm下命名为1.txt.bz2,并保留原文件
bunzip2 1.txt.bz2 #将1.txt.bz2解压缩
注:bzip2不能压缩目录
bzcat 1.txt.bz2 #查看1.txt.bz2文件内容
<------------------------------------------------------------------------------------------------------------------------>
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# bzip2 1.txt
[root@kh-01 ~]# ls
1.txt.bz2 anaconda-ks.cfg test test2
[root@kh-01 ~]# bzip2 -d 1.txt.bz2
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# bzip2 1.txt
[root@kh-01 ~]# ls
1.txt.bz2 anaconda-ks.cfg test test2
[root@kh-01 ~]# bunzip2 1.txt.bz2
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# bzip2 -c 1.txt > test2/2.txt.bz2
[root@kh-01 ~]# ls test2/
2.txt.bz2 test.txt
[root@kh-01 ~]# bzcat test2/2.txt.bz2
This is a test file.`rnd this is the first time to use "vim".
It is easy to use "vim".
I like to using it,do you like it?
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# bzip2 test2/
bzip2: Input file test2/ is a directory. #不能压缩目录
[root@kh-01 ~]#
<------------------------------------------------------------------------------------------------------------------------>
6.4 xz压缩工具
xz与bzip2用法相似,xz压缩率相对又更高些.
xz filename #压缩
xz -d filename.xz / unxz filename.xz #解压缩
xz -# filename #其中#范围1-9,默认6
xz -c 1.txt > /tmp/1.txt.xz #将1.txt压缩并将压缩后文件放到/tpm下命名为1.txt.xz,并保留原文件
xzcat 1.txt.xz #查看1.txt.xz文件内容
压缩率:
xz > bzip2 > gzip
注:xz不能压缩目录
<------------------------------------------------------------------------------------------------------------------------>
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# xz 1.txt
[root@kh-01 ~]# ls
1.txt.xz anaconda-ks.cfg test test2
[root@kh-01 ~]# xz -d 1.txt.xz
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# xz -9 1.txt
[root@kh-01 ~]# ls
1.txt.xz anaconda-ks.cfg test test2
[root@kh-01 ~]# unxz 1.txt.xz
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# ls test2/
test.txt
[root@kh-01 ~]# xz -c 1.txt > test2/3.txt.xz
[root@kh-01 ~]# ls test2/
3.txt.xz test.txt
[root@kh-01 ~]# xzcat test2/3.txt.xz
This is a test file.`rnd this is the first time to use "vim".
It is easy to use "vim".
I like to using it,do you like it?
[root@kh-01 ~]# ls
1.txt anaconda-ks.cfg test test2
[root@kh-01 ~]# xz test2/
xz: test2/: Is a directory, skipping #不能压缩目录
[root@kh-01 ~]#
<------------------------------------------------------------------------------------------------------------------------>
转载于:https://blog.51cto.com/13517946/2057859