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


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