linux的tar命令

來源:互聯網
上載者:User

tar命令是用來處理打包和解包,以下是我們常用時所需的命令:

1、解包:

# tar -zxvf file.tar.gz

以上的這個命令是將包解壓到目前的目錄,如果將包解壓到其他目錄下的話,則使用

# tar -zxvf file.tar.gz -C path

path代表的是解壓到的目錄。

2、打包:

# tar -zcvf file.tar.gz path

file.tar.gz是打包的包名稱,而path是打包的目標檔案路徑。

注意:

  • 參數v是顯示打包的檔案資訊,如果不需要顯示的話就不用加。
  • 參數z是壓縮與解壓的格式,一般尾碼都是gz,如果有看到尾碼是gz2的話,將參數z替換成j。

3、查看壓縮裡有哪些檔案

# tar -tf file.tar.gz

4、在/home中,比2012/05/30新的檔案才備份

# tar -N "2012/05/30" -zcvf home.tar.gz /home

5、備份home和/ect,但不備份/home/dante目錄

# tar --exclude /home/dante -zcvf myfile.tar.gz /home/* /etc

6、將/etc打包直接解壓到/tmp中,不產生壓縮文檔

# tar -zcvf - /etc | tar -zxvf - -C /tmp

這個動作有點像是 cp -r /etc /tmp 依舊是有其有用途的!要注意的地方在於輸出檔變成 - 而輸入檔也變成 - ,又有一個 | 存在,這分別代表 standard output, standard input 與管線命令啦!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.