Linux-壓縮與歸檔

壓縮: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]#
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末廉白,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子治力,更是在濱河造成了極大的恐慌蒙秒,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件宵统,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機马澈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門瓢省,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人痊班,你說我怎么就攤上這事勤婚。” “怎么了涤伐?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵馒胆,是天一觀的道長。 經(jīng)常有香客問我凝果,道長祝迂,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任器净,我火速辦了婚禮型雳,結(jié)果婚禮上纠俭,老公的妹妹穿的比我還像新娘。我一直安慰自己浪慌,他們只是感情好冤荆,可當(dāng)我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著权纤,像睡著了一般匙赞。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上妖碉,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天涌庭,我揣著相機與錄音,去河邊找鬼欧宜。 笑死坐榆,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的冗茸。 我是一名探鬼主播席镀,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼夏漱!你這毒婦竟也來了豪诲?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤挂绰,失蹤者是張志新(化名)和其女友劉穎屎篱,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡交播,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年重虑,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片秦士。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡缺厉,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出隧土,到底是詐尸還是另有隱情提针,我是刑警寧澤,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布曹傀,位于F島的核電站辐脖,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏卖毁。R本人自食惡果不足惜揖曾,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望亥啦。 院中可真熱鬧炭剪,春花似錦、人聲如沸翔脱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽届吁。三九已至错妖,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間疚沐,已是汗流浹背暂氯。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留亮蛔,地道東北人痴施。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像究流,于是被迫代替她去往敵國和親辣吃。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容