壓縮:gzip/gunzip跑揉、bzip2/bunzip2直撤、xz/unxz
歸檔:tar
歸檔+壓縮:zip
1. gzip, gunzip, zcat - compress or expand files
gzip:壓縮(壓縮后會刪除原文件)
gunzip:解壓縮(解壓縮后會刪除原壓縮文件)
zcat:直接查看壓縮后的文本文件內(nèi)容(建議不要查看大文件)
說明:
gzip职恳、gunzip均可以同時操作多個文件
沈跨;
gzip量九、gunzip壓縮/解壓縮文件支持通配符
黍檩;
gzip申钩、gunzip不能操作目錄次绘。
SYNOPSIS
gzip [OPTIONS] <file ...>
OPTIONS
-d --decompress --uncompress
Decompress(解壓縮).
gzip -d <file> 相當(dāng)于gunzip <file>
-# --fast --best
指定壓縮比(默認壓縮比為6,建議無特殊需求不要改變默認壓縮比)
-c --stdout --to-stdout
將壓縮結(jié)果輸出至標準輸出
gzip <file> 相當(dāng)于 gzip -c <file> > <file.gz>(輸出重定向)
EXAMPLES
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# gzip sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
總用量 4.0K
-rw-r--r-- 1 root root 1.4K 4月 4 23:43 sentinel.log.gz
[root@VM_0_171_centos tmp]# gzip -d sentinel.log.gz
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]#
2. bzip2/bunzip2/bzcat
bzip2:壓縮(壓縮后會刪除原文件)
bunzip2:解壓縮(解壓縮后會刪除原壓縮文件)
bzcat:直接查看壓縮后的文本文件內(nèi)容(建議不要查看大文件)
SYNOPSIS
bzip2 [OPTIONS] <file ...>
** OPTIONS**
-d:解壓縮
-#:指定壓縮比撒遣;默認是6邮偎;數(shù)字越大壓縮比越大(1-9);
-k:keep义黎,保留原文件禾进;
** EXAMPLES**
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# bzip2 sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
總用量 4.0K
-rw-r--r-- 1 root root 1.5K 4月 4 23:43 sentinel.log.bz2
[root@VM_0_171_centos tmp]# bzip2 -d sentinel.log.bz2
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# bzip2 -k sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
總用量 20K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
-rw-r--r-- 1 root root 1.5K 4月 4 23:43 sentinel.log.bz2
[root@VM_0_171_centos tmp]#
3. xz/unxz/xzcat
用法與bzip2基本相同,但這種格式不是很常見
SYNOPSIS
xz [option]... [file]...
** OPTIONS**
-d:解壓縮
-#:指定壓縮比廉涕;默認是6泻云;數(shù)字越大壓縮比越大(1-9);
-k:keep狐蜕,保留原文件宠纯;
** EXAMPLES**
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# xz sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
總用量 4.0K
-rw-r--r-- 1 root root 1.3K 4月 4 23:43 sentinel.log.xz
[root@VM_0_171_centos tmp]# xz -d sentinel.log.xz
[root@VM_0_171_centos tmp]# ls -lh
總用量 16K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
[root@VM_0_171_centos tmp]# xz -k sentinel.log
[root@VM_0_171_centos tmp]# ls -lh
總用量 20K
-rw-r--r-- 1 root root 13K 4月 4 23:43 sentinel.log
-rw-r--r-- 1 root root 1.3K 4月 4 23:43 sentinel.log.xz
[root@VM_0_171_centos tmp]#
4. tar - manual page for tar 1.26
歸檔文件或目錄
SYNOPSIS
tar [OPTION...] [FILE]...
OPTIONS
#創(chuàng)建歸檔(v選項用于顯示執(zhí)行過程)
tar -cvf /PATH/TO/file.tar <file ...>
#創(chuàng)建歸檔并壓縮成.gz格式
tar -zcvf /PATH/TO/file.tar <file ...>
#創(chuàng)建歸檔并壓縮成.bz2格式
tar -jcvf /PATH/TO/file.tar <file ...>
#展開歸檔
tar -xvf <file ...> [-C <展開至目標目錄>]
#解壓并展開歸檔(.gz)
tar -zxvf <file ...> [-C <展開至目標目錄>]
#解壓并展開歸檔(.bz2)
tar -jxvf <file ...> [-C <展開至目標目錄>]
#查看歸檔文件的文件列表
tar -tf <file>
EXAMPLES
下載nginx-1.10.3.tar.gz,解壓层释,再壓縮成.bz2格式
[root@VM_0_171_centos tmp]# ls
sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
--2017-04-11 22:44:56-- http://nginx.org/download/nginx-1.10.3.tar.gz
正在解析主機 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
正在連接 nginx.org (nginx.org)|206.251.255.63|:80... 已連接婆瓜。
已發(fā)出 HTTP 請求,正在等待回應(yīng)... 200 OK
長度:911509 (890K) [application/octet-stream]
正在保存至: “nginx-1.10.3.tar.gz”
100%[=========================================================>] 911,509 445KB/s 用時 2.0s
2017-04-11 22:44:59 (445 KB/s) - 已保存 “nginx-1.10.3.tar.gz” [911509/911509])
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3.tar.gz sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# tar -jcf nginx-1.10.3.tar.bz2 nginx-1.10.3
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.tar.bz2 nginx-1.10.3.tar.gz sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]#
5.zip - package and compress (archive) files
最通用的壓縮贡羔、打包工具
用法
zip file.zip <file ...>
unzip -d <解壓目錄> <file>
EXAMPLES
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# zip nginx-1.10.3.zip nginx-1.10.3/
adding: nginx-1.10.3/ (stored 0%)
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz
[root@VM_0_171_centos tmp]# zip test.zip nginx-1.10.3 sentinel.log
adding: nginx-1.10.3/ (stored 0%)
adding: sentinel.log (deflated 89%)
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz test.zip
[root@VM_0_171_centos tmp]# unzip -d ./test/ test.zip
Archive: test.zip
creating: ./test/nginx-1.10.3/
inflating: ./test/sentinel.log
[root@VM_0_171_centos tmp]# ls
nginx-1.10.3 nginx-1.10.3.zip sentinel.log sentinel.log.xz test test.zip
[root@VM_0_171_centos tmp]#