天天看點

2.5- 壓縮檔案 bzip2和gzip和zip指令詳解

windows系統,我們常用zip檔案,zip工具将大檔案壓縮為較小的檔案,以節省空間。

Linux系統提供了一些檔案壓縮工具,下表列出了Linux可用的檔案壓縮工具:

2.5- 壓縮檔案 bzip2和gzip和zip指令詳解

1、bzip2工具

bzip2工具是一個相對較新的壓縮包,它壓縮大型二進制檔案方面日益普及。

bzip2工具包含以下幾種:

1> bzip2 檔案名,bzip2:壓縮檔案

預設情況下,bzip2指令嘗試壓縮原始檔案,并将它替換為壓縮後的檔案,壓縮後的檔案名相同,但使用.bz2擴充名:

[[email protected] tmp]# ls -lh services 
-rw-r--r--. 1 root root 655K 8月  12 23:28 services
[[email protected] tmp]# bzip2 services 
[[email protected] tmp]# ls -lh services* 
-rw-r--r--. 1 root root 122K 8月  12 23:28 services.bz2
           

services檔案初始大小為655K,經過bzip2壓縮後,隻有122K.

注意點:

  • bzip2指令字段使用.bz2擴充名對原始檔案進行重命名,擴充名訓示了檔案所使用的壓縮技術
  • bzip2指令壓縮後,原始檔案不再存在

2> bzcat 壓縮檔案夾,bzcat:顯示已壓縮文本檔案的内容

檔案壓縮之後,無法使用正常的檢視檔案指令 cat 、more、less來檢視資料,需要使用 bzcat指令:

[[email protected] tmp]# bzcat services.bz2  
           

3> bunzip2 壓縮檔案名,bunzip2:解壓.bz2檔案

解壓後的檔案将傳回初始檔案大小

bzcat指令用于顯示壓縮檔案内部的檔案,無需解壓實際的檔案。

[[email protected] tmp]# bunzip2 services.bz2 
[[email protected] tmp]# ls -lh services* 
-rw-r--r--. 1 root root 655K 8月  12 23:28 services
           

4> bzip2recover:嘗試回複受損的壓縮檔案

2、gzip工具

gzip工具是Linux中最流行的檔案壓縮工具。

gzip工具包含以下幾種:

1> gzip 檔案名,gzip:壓縮檔案

gip指令将壓縮指令行中指定的檔案

[[email protected] tmp]# gzip services 
[[email protected] tmp]# ls -lh services*
-rw-r--r--. 1 root root 133K 8月  12 23:28 services.gz
           

gzip可以指定多個檔案名,或者與通配符配合使用一次壓縮多個檔案:

[[email protected] tmp]# ls -lh services*
-rw-r--r--. 1 root root 655K 8月  12 23:28 services
-rw-r--r--. 1 root root 655K 8月  12 23:41 services1
-rw-r--r--. 1 root root 655K 8月  12 23:41 services2
[[email protected] tmp]# gzip services*
[[email protected] tmp]# ls -lh services*
-rw-r--r--. 1 root root 133K 8月  12 23:41 services1.gz
-rw-r--r--. 1 root root 133K 8月  12 23:41 services2.gz
-rw-r--r--. 1 root root 133K 8月  12 23:28 services.gz
           

2> gzcat 壓縮檔案名,gzcat:顯示壓縮後的文本檔案的内容

3> gunzip 壓縮檔案名,gunzip :解壓檔案

3、zip工具