日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

6.1-6.4 gzip、Bzip2、xz

發(fā)布時間:2025/3/18 编程问答 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 6.1-6.4 gzip、Bzip2、xz 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

6.1 壓縮打包介紹

Linux環(huán)境常見壓縮文件類型:

.zip,.gz,.bz2,.xz,

.tar.gz,.tar.bz2,.tar.xz

壓縮打包的目的

  • 方便文件傳輸

  • 節(jié)省磁盤空間

  • 減少傳輸花費的時間

  • 節(jié)省帶寬


6.2 gzip壓縮工具

gzip是GNUzip的縮寫,它是一個GNU自由軟件的文件壓縮程序,用于UNIX系統(tǒng)的文件壓縮。我們在Linux中經(jīng)常會用到后綴為.gz的文件,它們就是gzip格式的。

注意:?gzip不能壓縮目錄文件

語法:?gzip [options] [filename]

options:

-d:解壓縮(=gunzip)

-#:指定壓縮等級,此處#表示1~9數(shù)字,9壓縮最好,默認(rèn)為6(壓縮等級越高,CPU消耗越高)

壓縮

直接壓縮:

[root@gaohawnei d6z]# find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \; 創(chuàng)建一個文件并寫入內(nèi)容?

[root@gaohanwei d6z]# du -sh 1.txt ? 文件壓縮前大小?

2.2M 1.txt?

[root@gaohanwei d6z]# wc -l 1.txt ? 查看其內(nèi)容總行數(shù)?

32235 1.txt?

[root@gaohanwei d6z]# gzip 1.txt ?壓縮?

[root@gaohanwei d6z]# ls 1.txt. ? ? ? ? ? ? ? ? ? 壓縮后,源文件會消失?

[root@gaohanwei d6z]# du -sh 1.txt.gz 壓縮后文件大小?

328K 1.txt.gz?

[root@gaohanwei d6z]# file 1.txt.gz ? 查看文件屬性?

1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Thu?

Jun 22 14:54:25 2017

指定壓縮目錄:

[root@gaohanwei d6z]# gzip -c 1.txt > /tmp/1.txt.gz?

[root@gaohanwei d6z]# ls /tmp/1.txt.gz /tmp/1.txt.gz?

[root@gaohanwei d6z]# ls ? 1.txt ? ? ? ? ? ? ? ?壓縮完成后源文件不會消失

查看壓縮包內(nèi)容:

使用zcat命令:

[root@gaohanwei d6z]# zcat 1.txt.gz ? 可查看壓縮文件內(nèi)部內(nèi)容

解壓

直接解壓:

gzip -d

[root@gaohanwei d6z]# gzip -d 1.txt.gz ?解壓?

[root@gaohanwei d6z]# ls 1.txt ? ? ? ?解壓后壓縮文件消失?

[root@gaohanwei d6z]# du -sh 1.txt 1.3M 1.txt ? ? ?解壓后較原文件變小 ??

[root@gaohanwei d6z]# wc -l !$ wc -l 1.txt 32235 1.txt

gunzip

[root@gaohanwei d6z]# gunzip 1.txt.gz?

[root@gaohanwei d6z]# ls 1.txt

指定解壓目錄

[root@gaohanwei d6z]# gunzip -c /tmp/1.txt.gz > ./2.txt?

[root@gaohanwei d6z]# ls 1.txt ?2.txt?

[root@gaohanwei d6z]# ls /tmp/1.txt.gz /tmp/1.txt.gz ? ? ? ? 解壓后原壓縮文件不會消失?

[root@gaohanwei d6z]# wc 1.txt 2.txt ?內(nèi)容不變 ?

32235 ?169760 1277475 1.txt ?

32235 ?169760 1277475 2.txt ?

64470 ?339520 2554950 總用量?

[root@gaohanwei d6z]# du -sh *.txt ?大小不變?

1.3M ? 1.txt?

1.3M ? 2.txt


6.3 bzip2 壓縮工具

bzip2 是一個基于Burrows-Wheeler 變換的無損壓縮軟件,壓縮效果比傳統(tǒng)的LZ77/LZ78壓縮算法來得好。它是一款免費軟件。可以自由分發(fā)免費使用。它廣泛存在于UNIX&LINUX的許多發(fā)行版本中。bzip2能夠進(jìn)行高質(zhì)量的數(shù)據(jù)壓縮。它利用先進(jìn)的壓縮技術(shù),能夠把普通的數(shù)據(jù)文件壓縮10%至15%,壓縮的速度和解壓的效率都非常高!支持大多數(shù)壓縮格式,包括tar、gzip 等等。

注意:?bzip2不可以壓縮目錄文件

語法:?bzip2 [options] [filename]

options:

-d:解壓縮

-z:壓縮(=bzip2,所以可以不帶該參數(shù)直接使用)

bzip2的使用方法同gzip。

壓縮

[root@gaohanwei d6z]# bzip2 1.txt?

[root@gaohanwei d6z]# ls?

1.txt.bz2 ?2.txt?

[root@gaohanwei d6z]# du -sh 1.txt.bz2?

156K 1.txt.bz2 ? ? ?較gzip壓縮程度更高?

[root@gaohanwei d6z]#

解壓

[root@gaohanwei d6z]# bzip2 -d 1.txt.bz2 ?方法1?

[root@gaohanwei d6z]# ls?

1.txt ?2.txt?

[root@gaohanwei d6z]# du -sh *.txt?

1.3M ? 1.txt?

1.3M ? 2.txt?

#####################################?

[root@gaohanwei d6z]# bzip2 -z 1.txt?

[root@gaohanwei d6z]# ls?

1.txt.bz2 ?2.txt?

[root@gaohanwei d6z]# bunzip2 1.txt.bz2 ? 方法2?

[root@gaohanwei d6z]# ls?

1.txt ?2.txt?

[root@gaohanwei d6z]# !du du -sh *.txt?

1.3M ? 1.txt?

1.3M ? 2.txt

說明:?同gzip,該命令也可指定目錄進(jìn)行壓縮和解壓。

案例:

情景:?查看某目錄文件時里面有一個文件1.txt,使用cat等命令查看其內(nèi)容時出現(xiàn)如下提示:"1.txt" may be a binary file. See it anyway? 。此時按‘y’,屏幕會出現(xiàn)一堆亂碼,趕緊按q退出,然后查找器原因:使用file命令!

[root@gaohanwei d6z]# ls?

1.txt ?2.txt?

[root@gaohanwei d6z]# less 1.txt?

"1.txt" may be a binary file. ?See it anyway??

[root@gaohanwei d6z]# file 1.txt?

1.txt: bzip2 compressed data, block size = 900k

由file命令查看該文件信息后得知其為‘.bz2’壓縮文件,即使用bzcat命令即可查看,并更改其文件名為正確格式以防再次被誤導(dǎo)。

[root@gaohanwei d6z]# bzcat 1.txt?

由于內(nèi)容太多,在此不做演示?

[root@gaohanwei d6z]# mv 1.txt 1.txt.bz2


6.4 xz壓縮工具

xz是一種壓縮文件格式,采用LZMA SDK壓縮,目標(biāo)文件較gzip壓縮文件(.gz或·tgz)小30%,較·bz2小15%。

注意:?xz不可用于壓縮目錄文件

語法:?xz [options] [filename]

options:

-d:解壓縮

使用方法同gzip、bzip2,壓縮程度更高。

壓縮

[root@gaohanwei d6z]# xz 2.txt?

[root@gaohanwei d6z]# ls?

1.txt ?2.txt.xz?

[root@gaohanwei d6z]# du -sh 2.txt.xz?

60K ? ?2.txt.xz?

[root@gaohanwei d6z]# file 2.txt.xz ??

2.txt.xz: XZ compressed data?

[root@gaohanwei d6z]# xzcat 2.txt.xz 查看壓縮文件內(nèi)容

解壓

[root@gaohanwei d6z]# xz -d 2.txt.xz ? 方法1?

[root@gaohanwei d6z]# ls?

1.txt ?2.txt?

[root@gaohanwei d6z]# du -sh 2.txt?

1.3M ? 2.txt?

################################?

[root@gaohanwei d6z]# unxz 2.txt.xz ? 方法2?

[root@gaohanwei d6z]# ls?

1.txt ?2.txt

說明:?同gzip、bzip2,該命令也可指定目錄進(jìn)行壓縮和解壓。


轉(zhuǎn)載于:https://blog.51cto.com/13530586/2057649

總結(jié)

以上是生活随笔為你收集整理的6.1-6.4 gzip、Bzip2、xz的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。