linux 中gzip、bzip2、xz压缩、解压缩
001、gzip
[root@PC1 test]# ls a.txt [root@PC1 test]# ll -h total 39M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt [root@PC1 test]# gzip -c a.txt > a.txt.gz ## 压缩 [root@PC1 test]# ll -h total 49M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 11M Dec 7 11:46 a.txt.gz [root@PC1 test]# ls a.txt a.txt.gz [root@PC1 test]# gzip -dc a.txt.gz > b.txt ## 解压 [root@PC1 test]# ls a.txt a.txt.gz b.txt [root@PC1 test]# ll -h total 87M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 11M Dec 7 11:46 a.txt.gz -rw-r--r--. 1 root root 39M Dec 7 11:46 b.txt

。
002、bzip2
[root@PC1 test]# ls a.txt [root@PC1 test]# bzip2 -c a.txt > a.txt.bz2 ## 压缩 [root@PC1 test]# ll -h total 44M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 5.5M Dec 7 11:52 a.txt.bz2 [root@PC1 test]# bzip2 -dc a.txt.bz2 > b.txt ## 解压 [root@PC1 test]# ls a.txt a.txt.bz2 b.txt [root@PC1 test]# ll -h total 82M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 5.5M Dec 7 11:52 a.txt.bz2 -rw-r--r--. 1 root root 39M Dec 7 11:52 b.txt

.
003、xz
[root@PC1 test]# ls a.txt [root@PC1 test]# xz -c a.txt > a.txt.xz [root@PC1 test]# ll -h total 39M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 568K Dec 7 11:54 a.txt.xz [root@PC1 test]# xz -dc a.txt.xz > b.txt [root@PC1 test]# ls a.txt a.txt.xz b.txt [root@PC1 test]# ll -h total 77M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 568K Dec 7 11:54 a.txt.xz -rw-r--r--. 1 root root 39M Dec 7 11:54 b.txt

。
004、三者极致压缩效率的对比
[root@PC1 test]# ls a.txt [root@PC1 test]# ll -h total 39M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt [root@PC1 test]# gzip -9 -c a.txt > gzip.gz [root@PC1 test]# bzip2 -9 -c a.txt > bzip2.bz2 [root@PC1 test]# xz -9 -c a.txt > xz.xz [root@PC1 test]# ll -h total 55M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 5.5M Dec 7 11:56 bzip2.bz2 -rw-r--r--. 1 root root 11M Dec 7 11:56 gzip.gz -rw-r--r--. 1 root root 407K Dec 7 11:57 xz.xz

。
005、与打包命令tar的结合
[root@PC1 test]# ls a.txt b.txt [root@PC1 test]# ll -h total 77M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 39M Dec 7 11:59 b.txt [root@PC1 test]# tar -czf gzip.tar.gz a.txt b.txt [root@PC1 test]# tar -cjf gzip.tar.bz2 a.txt b.txt [root@PC1 test]# tar -cJf gzip.tar.xz a.txt b.txt [root@PC1 test]# ls a.txt b.txt gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# ll -h total 109M -rw-r--r--. 1 root root 39M Dec 7 11:28 a.txt -rw-r--r--. 1 root root 39M Dec 7 11:59 b.txt -rw-r--r--. 1 root root 11M Dec 7 12:00 gzip.tar.bz2 -rw-r--r--. 1 root root 21M Dec 7 11:59 gzip.tar.gz -rw-r--r--. 1 root root 945K Dec 7 12:00 gzip.tar.xz

。
006、解包
[root@PC1 test]# ls gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# tar -xzf gzip.tar.gz [root@PC1 test]# ls a.txt b.txt gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# rm a.txt b.txt [root@PC1 test]# ls gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# tar xjf gzip.tar.bz2 [root@PC1 test]# ls a.txt b.txt gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# rm a.txt b.txt [root@PC1 test]# ls gzip.tar.bz2 gzip.tar.gz gzip.tar.xz [root@PC1 test]# tar -xJf gzip.tar.xz [root@PC1 test]# ls a.txt b.txt gzip.tar.bz2 gzip.tar.gz gzip.tar.xz

。

浙公网安备 33010602011771号