日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

6.1-6.4 gzip、Bzip2、xz

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

6.1 壓縮打包介紹

Linux環境常見壓縮文件類型:

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

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

壓縮打包的目的

  • 方便文件傳輸

  • 節省磁盤空間

  • 減少傳輸花費的時間

  • 節省帶寬


6.2 gzip壓縮工具

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

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

語法:?gzip [options] [filename]

options:

-d:解壓縮(=gunzip)

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

壓縮

直接壓縮:

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

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

2.2M 1.txt?

[root@gaohanwei d6z]# wc -l 1.txt ? 查看其內容總行數?

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 ? ? ? ? ? ? ? ?壓縮完成后源文件不會消失

查看壓縮包內容:

使用zcat命令:

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

解壓

直接解壓:

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 ?內容不變 ?

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 變換的無損壓縮軟件,壓縮效果比傳統的LZ77/LZ78壓縮算法來得好。它是一款免費軟件。可以自由分發免費使用。它廣泛存在于UNIX&LINUX的許多發行版本中。bzip2能夠進行高質量的數據壓縮。它利用先進的壓縮技術,能夠把普通的數據文件壓縮10%至15%,壓縮的速度和解壓的效率都非常高!支持大多數壓縮格式,包括tar、gzip 等等。

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

語法:?bzip2 [options] [filename]

options:

-d:解壓縮

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

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,該命令也可指定目錄進行壓縮和解壓。

案例:

情景:?查看某目錄文件時里面有一個文件1.txt,使用cat等命令查看其內容時出現如下提示:"1.txt" may be a binary file. See it anyway? 。此時按‘y’,屏幕會出現一堆亂碼,趕緊按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命令即可查看,并更改其文件名為正確格式以防再次被誤導。

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

由于內容太多,在此不做演示?

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


6.4 xz壓縮工具

xz是一種壓縮文件格式,采用LZMA SDK壓縮,目標文件較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 查看壓縮文件內容

解壓

[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,該命令也可指定目錄進行壓縮和解壓。


轉載于:https://blog.51cto.com/13530586/2057649

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。