6.2 gzip:压缩或解压文件
生活随笔
收集整理的這篇文章主要介紹了
6.2 gzip:压缩或解压文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
gzip命令
用于將一個大的文件通過壓縮算法(Lempel-Ziv coding(LZ77))變成一個小的文件。gzip命令不能直接壓縮目錄,因此目錄需要先用tar打包成一個文件,然后tar再調用gzip進行壓縮。 -d?? ?解開壓縮文件 -v?? ?顯示指令執行的過程 -l?? ?列出壓縮文件的內容信息 -c?? ?將內容輸出到標準輸出,不改變原始文件 -r?? ?對目錄下的所有文件遞歸進行壓縮操作 -數字<1-9>?? ?指定壓縮率,默認為6,值越大壓縮率越高 -t?? ?測試,檢查壓縮文件是否完整把目錄下的每個文件都壓縮成單獨的.gz文件
[root@cs6 html]# ls 10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy [root@cs6 html]# gzip *.html [root@cs6 html]# ls 10.html.gz 2.html.gz 4.html.gz 6.html.gz 8.html.gz oldboy 1.html.gz 3.html.gz 5.html.gz 7.html.gz 9.html.gz不解壓顯示上一個例子中每個壓縮文件的信息。 [root@cs6 html]# gzip -l *.gzcompressed uncompressed ratio uncompressed_name28 0 0.0% 10.html27 0 0.0% 1.html27 0 0.0% 2.html27 0 0.0% 3.html27 0 0.0% 4.html27 0 0.0% 5.html27 0 0.0% 6.html27 0 0.0% 7.html27 0 0.0% 8.html27 0 0.0% 9.html [root@cs6 html]# ls 10.html.gz 2.html.gz 4.html.gz 6.html.gz 8.html.gz oldboy 1.html.gz 3.html.gz 5.html.gz 7.html.gz 9.html.gz解壓文件,并顯示解壓過程
[root@cs6 html]# gzip -dv *.gz #<==使用-d參數解壓文件,使用-v參數顯示解壓過程。 10.html.gz: 0.0% -- replaced with 10.html 1.html.gz: 0.0% -- replaced with 1.html 2.html.gz: 0.0% -- replaced with 2.html 3.html.gz: 0.0% -- replaced with 3.html 4.html.gz: 0.0% -- replaced with 4.html 5.html.gz: 0.0% -- replaced with 5.html 6.html.gz: 0.0% -- replaced with 6.html 7.html.gz: 0.0% -- replaced with 7.html 8.html.gz: 0.0% -- replaced with 8.html 9.html.gz: 0.0% -- replaced with 9.html [root@cs6 html]# ls 10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html oldboy [root@cs6 html]#壓縮解壓保留源文件
[root@cs6 html]# cp /etc/services . [root@cs6 html]# ll -h services -rw-r--r--. 1 root root 626K May 13 00:29 services [root@cs6 html]# gzip -c services >services.gz #<==使用-c 選項與輸出重定向符號將輸出定向到services.gz。 [root@cs6 html]# ll -h services* -rw-r--r--. 1 root root 626K May 13 00:29 services -rw-r--r--. 1 root root 125K May 13 00:30 services.gz #<==使用-d選項解壓。 [root@cs6 html]# gzip -dc services.gz >services2 [root@cs6 html]# diff services services2 #<==對比源文件和解壓后的文件,沒有差別。 [root@cs6 html]# ll -h services* -rw-r--r--. 1 root root 626K May 13 00:29 services -rw-r--r--. 1 root root 626K May 13 00:31 services2 -rw-r--r--. 1 root root 125K May 13 00:30 services.gz經驗技巧
雖然上面使用重定向符號解決了保留源文件的問題,但是使用起來還是不太方便,因此這里告訴大家一個好方法:gzip套件包含了許多可以“在原地”處理壓縮文件的實用程序。zcat、zgrep、zless、zdiff等實用程序的作用分別與cat、grep、less和diff相同,但是它們操作的是壓縮的文件。比如: [root@cs6 html]# zcat services.gz |head # /etc/services: # $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $ # # Network services, Internet style # IANA services version: last updated 2009-11-10 # # Note that it is presently the policy of IANA to assign a single well-known # port number for both TCP and UDP; hence, most entries here have two entries # even if the protocol doesn't support UDP operations. # Updated from RFC 1700, ``Assigned Numbers'' (October 1994). Not all ports [root@cs6 html]# zcat services.gz >services #也可以直接解壓出來重定向到文件。 [root@cs6 html]#總結
以上是生活随笔為你收集整理的6.2 gzip:压缩或解压文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 6.1 tar:打包备份
- 下一篇: 6.6 rsync:文件同步工具