標籤:檔案壓縮 壓縮檔 二進位 linux 空間
什麼是壓縮檔?原理是什麼?
簡單的說,就是經過壓縮軟體壓縮檔叫壓縮檔,壓縮的原理是把檔案的二進位代碼壓縮,把相鄰的0,1代碼減少,
例如有000000,可以把它變成6個0的寫法60來減少該檔案的空間,同理解壓縮就是按照相同的原則把資料還原回來。
Linux環境中有哪些格式的壓縮檔?
常見的壓縮檔有*.tar,*.tar.gz,*.tgz,*.gz,*.Z,*.bz2,為啥有這麼多種壓縮檔?這是因為Linux支援的壓縮命令非常多,
且不同的命令所用的壓縮技術並不相同,當然彼此之前可能就無法互連壓縮/解壓縮了。
下面是不同格式的壓縮檔對應的壓縮程式:
650) this.width=650;" title="image_thumb[2]" style="border:0px;width:421px;height:137px;" border="0" alt="image_thumb[2]" src="http://img1.51cto.com/attachment/201407/1/8926377_1404232688DemJ.png" height="137" width="421" hspace="0" vspace="0" />
Linux上常見的壓縮命令就是gzip和bzip2, compress已經不流行了!
gzip介紹:
使用:gzip [選項] 檔案名稱
選項:
650) this.width=650;" title="image_thumb[6]" style="border:0px;width:420px;height:140px;" border="0" alt="image_thumb[6]" src="http://img1.51cto.com/attachment/201407/1/8926377_1404232688L7K9.png" height="140" width="420" hspace="0" vspace="0" />
用法:
1.#gzip filename 不加參數會刪除原來的檔案
2.#gzip –c filename > filename.gz 將壓縮檔重新導向輸出
3.#gzip –d filename.gz 將解壓檔案
4.#gunzip filename.gz 將解壓檔案,會刪除原有的filename.gz檔案
5.#zcat filename.gz 不解壓查看檔案
bzip2介紹:
使用:bzip2 [選項] 檔案名稱
選項:
650) this.width=650;" title="image_thumb[9]" style="border:0px;width:427px;height:147px;" border="0" alt="image_thumb[9]" src="http://img1.51cto.com/attachment/201407/1/8926377_14042326898ewG.png" height="147" width="427" hspace="0" vspace="0" />
用法:
1.#bzip2 filename 不加參數會刪除原來的檔案
2.#bzip2 –c filename > filename.bz2 將壓縮檔重新導向輸出
3.#bzip2 –d filename.bz2 將解壓檔案
4.#bunbzip2 filename.bz2 將解壓檔案,會刪除原有的filename.bz2檔案
5.#bzcat filename.bz2 不解壓查看檔案
如何對目錄進行壓縮?
壓縮程式可以對單一檔案進行壓縮,而不能對目錄直接壓縮成一個壓縮檔,需要打包後才能壓縮,這裡介紹打包命令:tar
tar介紹:
選項:
650) this.width=650;" title="image_thumb[12]" style="border:0px;width:433px;height:162px;" border="0" alt="image_thumb[12]" src="http://img1.51cto.com/attachment/201407/1/8926377_1404232689PKF5.png" height="162" width="433" hspace="0" vspace="0" />
用法:
1.#tar -cf directoryName.tar directoryName 建立一個包檔案
2.#tar -zcv -f directoryName.tar.gz directoryName 先建立tar打包檔案然後用gzip壓縮,並顯示檔案清單
3.#tar -zcv -f directoryName.tar.gz directoryName 先建立tar打包檔案然後用gzip壓縮,並顯示檔案清單
4.#tar -ztv -f filename.tar.gz 不解壓查看打包檔案內的所有檔案清單
5.#tar zxv -f filename.tar.gz 用gzip解壓縮,然後將打包檔案展開到目前的目錄
6.#tar zxv -f filename.tar.gz –C /tmp 用gzip解壓縮,然後將打包檔案展開到tmp目錄