標籤:linux tar
1 gzip
[[email protected] ~]# gzip a.sh #壓縮後檔案尾碼為.gz
[[email protected] ~]# gzip -d a.sh.gz #解壓gz檔案
[[email protected] ~]# zcat a.sh.gz #查看壓縮檔
2 bzip
[[email protected] ~]# bzip2 a.sh #壓縮後檔案尾碼為bz2
[[email protected] ~]# bzip2 a.sh.bz2 -d #解壓檔案
[[email protected] ~]# bzcat a.sh.bz2 #查看壓縮檔
備忘:gzip和bzip2目前不支援對目錄的壓縮
3 zip:支援對目錄的壓縮
選項:-r 遞迴壓縮
-d 指定解壓目錄
-o 不提示的情況下覆蓋原檔案
[[email protected] /]# zip -r root.zip /root/* #壓縮
[[email protected] ~]# unzip -o -d /c root.zip #解壓到根下的C目錄下
4 tar:打包與解包檔案
用法:tar [主選項+次選項] 路徑... #主選項是必須的,次選項可以選用
主選項:-c 建立打包檔案
-x 釋放打包檔案
-t 列出打包的文檔的內容
-r 追加檔案到打包檔案
--delete 從打包檔案中刪除檔案
次選項:-C 指定解壓路徑
-f 指定打包的名稱
-z 打包後通過gzip格式壓縮
-j 打包後通過bzip2格式壓縮
-P 保留原檔案的屬性,如檔案的許可權
[[email protected] /]# tar -czf etc.tar.gz /etc/ #打包並壓縮目錄
[[email protected] /]# tar -tf etc.tar.gz #列出打包文檔的內容
[[email protected] /]# tar -xzf etc.tar.gz -C /c #把檔案解壓到C目錄下
[[email protected] /]# tar -rf a.tar /root/a.txt #把檔案追加到歸檔包中
[[email protected] /]# tar --delete root/a.txt -f /a.tar#從打包檔案中刪除a.txt
本文出自 “一萬年太久,只爭朝夕” 部落格,請務必保留此出處http://zengwj1949.blog.51cto.com/10747365/1916770
linux命令之壓縮及解壓縮