linux基礎--壓縮及歸檔

gzip

 只能壓縮文件,不能壓縮目錄,壓縮後會刪除源文件

gzip:壓縮後綴爲.gz

 -#:1-9指定壓縮比,默認爲6

 -d:解壓縮

[root@localhost study]# gzip messages   #壓縮完成後會刪除源文件
[root@localhost study]# ll
total 8
-rw-------. 1 root root 6828 Dec 23 22:22 messages.gz
[root@localhost study]# gzip -d messages   #解壓縮
[root@localhost study]# ll
total 336
-rw-------. 1 root root 340117 Dec 23 22:22 messages

gzip解壓縮

gunzip

[root@localhost study]# gunzip messages.gz   解壓縮
[root@localhost study]# ll
total 336
-rw-------. 1 root root 340117 Dec 23 22:22 messages

zcat:不解壓gzip查看gzip壓縮包內容

[root@localhost study]# zcat messages.gz


bzip2

 bzip2相對於gzip有更大的壓縮比,只能壓縮文件,壓縮後會刪除源文件

 -k:保留源文件

壓縮
[root@localhost study]# bzip2 messages 
[root@localhost study]# ls -lh
total 8.0K
-rw-------. 1 root root 4.8K Dec 23 22:22 messages.bz2

bunzip2:解壓縮

[root@localhost study]# bunzip2 messages.bz2 
[root@localhost study]# ls -lh
total 336K
-rw-------. 1 root root 333K Dec 23 22:22 messages

bzcat:不解壓bzip2查看壓縮包內容

[root@localhost study]# bzcat messages.bz2

xz

 壓縮比更大,命令格式和上面兩個一樣

壓縮
[root@localhost study]# xz message
[root@localhost study]# ls -lh
total 8.0K
-rw-------. 1 root root 4.9K Dec 23 22:22 messages.xz
解壓縮
[root@localhost study]# xz -d messages.xz


zip

 壓縮後默認保留源文件,支持歸檔壓縮

 zip FILENAME.zip FILE1 FILE2 ...

[root@localhost study]# zip messages.zip messages    #壓縮單個文件
  adding: messages (deflated 98%)
[root@localhost study]# ls -lh
total 344K
-rw-------. 1 root root 333K Dec 23 22:22 messages
-rw-r--r--. 1 root root 6.9K Dec 23 22:42 messages.zip
[root@localhost study]# zip messages.zip messages messages01 messages02   #歸檔壓縮多個文件
  adding: messages (deflated 98%)
  adding: messages01 (deflated 98%)
  adding: messages02 (deflated 98%)
[root@localhost study]# ls -lh
total 1.1M
-rw-------. 1 root root 333K Dec 23 22:22 messages
-rw-------. 1 root root 333K Dec 23 22:44 messages01
-rw-------. 1 root root 333K Dec 23 22:44 messages02
-rw-r--r--. 1 root root  21K Dec 23 22:44 messages.zip

unzip:解壓縮

[root@localhost study]# unzip messages.zip 
Archive:  messages.zip
  inflating: messages                
  inflating: messages01              
  inflating: messages02              
[root@localhost study]# ls -lh
total 1.1M
-rw-------. 1 root root 333K Dec 23 22:22 messages
-rw-------. 1 root root 333K Dec 23 22:44 messages01
-rw-------. 1 root root 333K Dec 23 22:44 messages02
-rw-r--r--. 1 root root  21K Dec 23 22:44 messages.zip


tar

 歸檔工具,只歸檔不壓縮

 -c:創建歸檔文件

 -f FILE.tar:操作歸檔文件

 --xattrs:歸檔時保留文件擴展屬性信息

 -x:解開歸檔文件

 -t:不展開歸檔,查看歸檔了哪些文件

 -zcf:歸檔並調用gzip壓縮

 -zxf:歸檔並調用gzip解壓縮

 -jcf:歸檔並調用bzip2壓縮

 -jxf:歸檔並調用bzip2解壓縮

 -Jcf:歸檔並調用xz壓縮

 -Jxf:歸檔並調用xz解壓縮

歸檔並調用xz壓縮
[root@localhost study]# tar -Jcvf messages.tar.xz messages
[root@localhost study]# ls -lh
-rw-r--r--. 1 root root   5056 Dec 23 22:56 messages.tar.xz
歸檔並調用gzip壓縮
[root@localhost study]# tar -zcvf messages.tar.gz messages
[root@localhost study]# ls -lh
-rw-r--r--. 1 root root 6.8K Dec 23 22:58 messages.tar.gz


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章