壓縮打包介紹
在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