61 壓縮打包介紹
壓縮過后文件大小降低可以減少帶寬量
6.2 gzip壓縮工具
[root@localhost d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \;(將所有/etc/下的conf文件寫入1.txt)
[root@localhost d6z]# ls -lh
總用量 212K
-rw-r--r--. 1 root root 211K 1月 9 11:56 1.txt
[root@localhost d6z]# gzip 1.txt(壓縮1.txt)
[root@localhost d6z]# ls -lh
總用量 56K
-rw-r--r--. 1 root root 54K 1月 9 11:56 1.txt.gz
[root@localhost d6z]# gzip -d 1.txt.gz (解壓)
[root@localhost d6z]# ls -lh
總用量 212K
-rw-r--r--. 1 root root 211K 1月 9 11:56 1.txt
[root@localhost d6z]# gzip -1 1.txt (指定壓縮級別香璃,范圍1-9,默認(rèn)6舟误,1級別為壓縮的最不厲害的葡秒,一般默認(rèn))
[root@localhost d6z]# ls -lh
總用量 64K
-rw-r--r--. 1 root root 63K 1月 9 11:56 1.txt.gz
[root@localhost d6z]# gunzip 1.txt.gz
[root@localhost d6z]# ls -lh
總用量 212K
-rw-r--r--. 1 root root 211K 1月 9 11:56 1.txt
[root@localhost d6z]# zcat 1.txt.gz(查看壓縮文件中的內(nèi)容)
[root@localhost d6z]# gzip -c 1.txt > /root/d6z/1.txt.gz(指定壓縮路徑及保存壓縮名稱,并保留原文件)
[root@localhost d6z]# ls
1.txt 1.txt.gz
[root@localhost d6z]# gunzip -c 1.txt.gz > /root/d6z/2.txt(指定解壓路徑及保存解壓縮名稱)
[root@localhost d6z]# ls
1.txt 2.txt
gzip不能壓縮目錄
63 bzip2壓縮工具
相較gzip壓縮bizp2更厲害
[root@localhost d6z]# yum install -y bzip2(安裝)
[root@localhost d6z]# bzip2 1.txt
[root@localhost d6z]# ls -lh
總用量 260K
-rw-r--r--. 1 root root 48K 1月 10 09:55 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月 10 09:56 2.txt
[root@localhost d6z]# bzip2 -d 1.txt.bz2
[root@localhost d6z]# ls -lh
總用量 424K
-rw-r--r--. 1 root root 211K 1月 10 09:55 1.txt
-rw-r--r--. 1 root root 211K 1月 10 09:56 2.txt
[root@localhost d6z]# bzip2 -d 1.txt.bz2
[root@localhost d6z]# ls -lh
總用量 424K
-rw-r--r--. 1 root root 211K 1月 10 09:55 1.txt
-rw-r--r--. 1 root root 211K 1月 10 09:56 2.txt
[root@localhost d6z]# bzip2 -c 1.txt > /root/d6z/1.txt.bz2
[root@localhost d6z]# ls -lh
總用量 472K
-rw-r--r--. 1 root root 211K 1月 10 09:55 1.txt
-rw-r--r--. 1 root root 48K 1月 10 10:33 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月 10 09:56 2.txt
[root@localhost d6z]# bunzip2 -c 1.txt.bz2 > /root/d6z/3.txt
[root@localhost d6z]# ls -lh
總用量 684K
-rw-r--r--. 1 root root 211K 1月 10 09:55 1.txt
-rw-r--r--. 1 root root 48K 1月 10 10:33 1.txt.bz2
-rw-r--r--. 1 root root 211K 1月 10 09:56 2.txt
-rw-r--r--. 1 root root 211K 1月 10 10:36 3.txt
[root@localhost d6z]# file 1.txt.bz2
1.txt.bz2: bzip2 compressed data, block size = 900k(查看文件格式)
bzip2也不支持壓縮目錄
64 xz壓縮工具
[root@localhost d6z]# xz -c 1.txt > /root/d6z/1.txt.xz
[root@localhost d6z]# ls
1.txt 1.txt.xz
[root@localhost d6z]# xz -d -c 1.txt.xz > /root/d6z/2.txt
[root@localhost d6z]# ls
1.txt 1.txt.xz 2.txt
壓縮得程度最大
不支持壓縮目錄