linux tar壓縮排除某個檔案夾的方法_Linux

來源:互聯網
上載者:User

一般直接用tar命令打包很簡單,直接使用 tar -zcvf test.tar.gz test 即可。

在很多時候,我們要對某一個目錄打包,而這個目錄下有幾十個子目錄和子檔案,我們需要在打包的時候排除其中1、2個目錄或檔案。

這時候我們在用tar命令打包的時候,增加參數 --exclude 就能達到目的。

例如:

我們以tomcat 為例,打包的時候我們要排除 tomcat/logs 目錄,命令如下:

tar -zcvf tomcat.tar.gz --exclude=tomcat/logs tomcat

如果要排除多個目錄,增加 --exclude 即可,如下命令排除logs和libs兩個目錄及檔案xiaoshan.txt:

tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs --exclude=tomcat/xiaoshan.txt tomcat

這裡要說一下注意事項:

大家都知道linux在使用tab鍵的時候會對目錄名稱自動補全,這很方便,大家也比較常用。

如我們輸入 tomcat/lo 的時候按tab鍵,命令列會自動產生 tomcat/logs/ ,對於目錄,最後會多一個 “/”

這裡大家要注意的時候,在我們使用tar 的--exclude 命令排除打包的時候,不能加“/”,否則還是會把logs目錄以及其下的檔案打包進去。

錯誤寫法:

tar -zcvf tomcat.tar.gz --exclude=tomcat/logs/ --exclude=tomcat/libs/ tomcat

正確寫法:

tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs tomcat

以上這篇linux tar壓縮排除某個檔案夾的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援雲棲社區。

聯繫我們

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