gzip
壓縮后的格式為:*.gz
這種壓縮方式不能保存原文件;且不能壓縮目錄
命令舉例:
#壓縮
[root@localhost tmp]# gzip buodo
[root@localhost tmp]# ls
buodo.gz
#解壓
[root@localhost tmp]# gunzip buodo.gz
[root@localhost tmp]# ls
buodo
tar
命令選項:
-z(gzip) 用gzip來壓縮/解壓縮文件
-j(bzip2) 用bzip2來壓縮/解壓縮文件
-v(verbose) 詳細報告tar處理的文件信息
-c(create) 創建新的檔案文件
-x(extract) 解壓縮文件或目錄
-f(file) 使用檔案文件或設備,這個選項通常是必選的。
命令舉例:
#壓縮
[root@localhost tmp]# tar -zvcf buodo.tar.gz buodo
[root@localhost tmp]# tar -jvcf buodo.tar.bz2 buodo
#解壓
[root@localhost tmp]# tar -zvxf buodo.tar.gz
[root@localhost tmp]# tar -jvxf buodo.tar.bz2
zip
與gzip相比:1)可以壓縮目錄; 2)可以保留原文件;
選項:
-r(recursive) 遞歸壓縮目錄內的所有文件和目錄
命令舉例:
#壓縮和解壓文件
[root@localhost tmp]# zip boduo.zip boduo
[root@localhost tmp]# unzip boduo.zip
#壓縮和解壓目錄
[root@localhost tmp]# zip -r Demo.zip Demo
adding: Demo/ (stored 0%)
adding: Demo/Test2/ (stored 0%)
adding: Demo/Test1/ (stored 0%)
adding: Demo/Test1/test4 (stored 0%)
adding: Demo/test3 (stored 0%)
[root@localhost tmp]# unzip Demo.zip
Archive: Demo.zip
creating: Demo/
creating: Demo/Test2/
creating: Demo/Test1/
extracting: Demo/Test1/test4
extracting: Demo/test3
bzip2
壓縮后的格式:.bz2
參數
-k 產生壓縮文件后保留原文件
1
命令舉例
#壓縮
[root@localhost tmp]# bzip2 boduo
[root@localhost tmp]# bzip2 -k boduo
#解壓
[root@localhost tmp]# bunzip2 boduo.bz2