壓縮打包介紹/gzip/bzip2/xz

壓縮打包介紹

在windows下我們常見的壓縮包格式有;.rar .zip .7z

而在linux我們常見的有;.zip .gz .bz2 .xz .tar.gz .tar.bz2 .tar.xz

在學(xué)習(xí)之前我們先做好準備工作,我們需要創(chuàng)建一個新的文件來做實驗,這里我選擇到/mnt目錄下創(chuàng)建一個新的文件

[root@localhost ~]# cd /mnt/

[root@localhost mnt]# mkdir test

[root@localhost mnt]# touch test/ceshi.txt

[root@localhost mnt]# find /etc/ -type f -name "*conf"

[root@localhost mnt]# find /etc/ -type f -name "*conf" -exec cat {} >> test/ceshi.txt \;

[root@localhost mnt]# cat test/ceshi.txt

gzip壓縮工具

打包文件命令;

[root@localhost test]# gzip ceshi.txt

[root@localhost test]# ls

ceshi.txt.gz

查看壓縮文件的內(nèi)容命令;

[root@localhost test]#?zcat ceshi.txt.gz

解壓縮命令;

[root@localhost test]# gzip -d ceshi.txt.gz

[root@localhost test]# ls

ceshi.txt

壓縮原文件的同時原本件不被替換掉;

[root@localhost test]# gzip -c ceshi.txt > /mnt/ceshi.txt.gz

gzip壓縮工具的壓縮級別有1-9個級別,gzip默認壓縮的級別為6,如果需要指定壓縮的級別,可按以下命令;

[root@localhost test]# gzip -# ceshi.txt

壓縮的級別越到,占用cpu資源就越大,gzip只能壓縮文件,不支持壓縮目錄!

bzip2壓縮工具

如果系統(tǒng)默認沒有安裝bzip2壓縮工具,則需要自己手動使用yum命令安裝;

[root@localhost test]# yum install -y bzip2

bzip2壓縮工具壓縮級別同樣為9級,bzip2相比gzip來說壓縮的更狠一些,這意味著耗費cpu的資源也就更狠一些。

同樣的bzip2壓縮工具的使用和gzip的使用基本一致

壓縮;bzip2 (文件名)

解壓縮;bzip2 -d 或者bunzip2?

查看壓縮文件內(nèi)容;bzcat

xz壓縮工具


xz壓縮工具和前兩者比,操作幾乎同樣,壓縮的比前兩者都更加狠。

壓縮;xz (文件名)

解壓縮;xz -d 或者unxz

查看壓縮文件內(nèi)容;xzcat

通過du命令,可以查看三種壓縮工具的壓縮文件的容量大小

[root@localhost test]# du -sh ceshi.txt

212K ceshi.txt

通過wc命令,可以查看文件內(nèi)容的行數(shù)

[root@localhost test]# wc -l ceshi.txt

5395 ceshi.txt

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容