linux命令之壓縮及解壓縮

來源:互聯網
上載者:User

標籤:linux tar

1 gzip

[[email protected] ~]# gzip a.sh                #壓縮後檔案尾碼為.gz

[[email protected] ~]# gzip -d a.sh.gz          #解壓gz檔案

[[email protected] ~]# zcat a.sh.gz             #查看壓縮檔


2 bzip

[[email protected] ~]# bzip2 a.sh               #壓縮後檔案尾碼為bz2

[[email protected] ~]# bzip2 a.sh.bz2 -d        #解壓檔案

[[email protected] ~]# bzcat a.sh.bz2           #查看壓縮檔

備忘:gzip和bzip2目前不支援對目錄的壓縮


3 zip:支援對目錄的壓縮

選項:-r    遞迴壓縮

      -d    指定解壓目錄

      -o    不提示的情況下覆蓋原檔案

[[email protected] /]# zip -r root.zip /root/*  #壓縮

[[email protected] ~]# unzip -o -d /c root.zip  #解壓到根下的C目錄下


4 tar:打包與解包檔案

用法:tar [主選項+次選項] 路徑...        #主選項是必須的,次選項可以選用

主選項:-c    建立打包檔案

        -x    釋放打包檔案

        -t    列出打包的文檔的內容

        -r    追加檔案到打包檔案

        --delete    從打包檔案中刪除檔案

次選項:-C    指定解壓路徑

        -f    指定打包的名稱

        -z    打包後通過gzip格式壓縮

        -j    打包後通過bzip2格式壓縮

        -P    保留原檔案的屬性,如檔案的許可權

[[email protected] /]# tar -czf etc.tar.gz /etc/        #打包並壓縮目錄

[[email protected] /]# tar -tf etc.tar.gz               #列出打包文檔的內容

[[email protected] /]# tar -xzf etc.tar.gz -C /c        #把檔案解壓到C目錄下

[[email protected] /]# tar -rf a.tar /root/a.txt        #把檔案追加到歸檔包中

[[email protected] /]# tar --delete root/a.txt -f /a.tar#從打包檔案中刪除a.txt




本文出自 “一萬年太久,只爭朝夕” 部落格,請務必保留此出處http://zengwj1949.blog.51cto.com/10747365/1916770

linux命令之壓縮及解壓縮

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.