转发:CentOS下tar压缩排除某个文件夹或文件及解压
生活随笔
收集整理的這篇文章主要介紹了
转发:CentOS下tar压缩排除某个文件夹或文件及解压
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?一、壓縮 一般直接用tar命令打包很簡單,直接使用 tar -zcvf test.tar.gz test 即可。 在很多時候,我們要對某一個目錄打包,而這個目錄下有幾十個子目錄和子文件,我們需要在打包的時候排除其中1、2個目錄或文件。 這時候我們在用tar命令打包的時候,增加參數(shù) --exclude 就能達(dá)到目的。 例如: 我們以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 這里要說一下注意事項(xiàng): 大家都知道linux在使用tab鍵的時候會對目錄名稱自動補(bǔ)全,這很方便,大家也比較常用。 如我們輸入 tomcat/lo 的時候按tab鍵,命令行會自動生成 tomcat/logs/ ,對于目錄,最后會多一個 “/” 這里大家要注意的時候,在我們使用tar 的--exclude 命令排除打包的時候,不能加“/”,否則還是會把logs目錄以及其下的文件打包進(jìn)去。 錯誤寫法: tar -zcvf tomcat.tar.gz --exclude=tomcat/logs/--exclude=tomcat/libs/tomcat 正確寫法: tar -zcvf tomcat.tar.gz --exclude=tomcat/logs --exclude=tomcat/libs tomcat
?二、解壓:
解壓到當(dāng)前目錄下
tar -zxvf shop.tar.gz解壓到指定目錄myshop
tar -zxvf shop.tar.gz -C myshop?
轉(zhuǎn)載于:https://www.cnblogs.com/firstcsharp/p/10535082.html
總結(jié)
以上是生活随笔為你收集整理的转发:CentOS下tar压缩排除某个文件夹或文件及解压的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TradingView 初识
- 下一篇: web服务器的原理