tar 的–exclude參數,實現不包括某些文件(轉)


最近有人問我tar壓縮能不能不包含不想要的文件或者文件夾 
壓縮包很利於傳送,備份等等。但比如大量的日志文件一般是不需要備份,或者需要分開備份。 
tar參數中的–exclude,這個是我在看鳥哥私房菜時看到的。當時覺得肯定有用,就多留意了幾眼,但使用的時候發現不是那么回事,所以后來就多研究了一下。沒想到現在對於備份來說很舒服~~~得心應手,如果要包含其他路徑的文件需要使用–include 
例子: 
在我的test文件夾下面,包含一些symbian的sisx安裝包及andoid包apk安裝包等等 
test的大致目錄結構:

[root@**** html]# tree -L 2 test
test
|--AndroidPad_v1.0.0_20111116_online_unsigned_1.apk
::|--KingGoo.Com.sh
|-- PACK_NAME.apk
|-- android.php
|-- androidpad.php
|-- bak
|`-- Vancl_2.0.0.0000_14_20120117_online_unsigned_versionCode_20.apk
|-- debug
|-- head.php
|-- index.php
|-- index1.php
|-- lingxin
|-- make.php
|-- make.sh
|-- make.sh.bk
|-- package.jar
|-- s60V3_1.2.1_2011-08-22-1755_online_signed.sis
::
|-- source_id.txt
|-- symbian.php
|-- temp
|   |-- AndroidPhone_v1.3.2_demo_unsign_versionCode7.apk_android
|   |-- KingGoo.Com_Err.log
|   |-- android
|   |-- androidpad
|   |-- make.log
|   |-- symbian
|   `-- temp
`-- test.php

8 directories, 86 files

 

我不想要*.sis、*.sisx、*.apk則:

 

[root@**** html]# tar -czvf  test.tar.gz  test --exclude=test/*.sisx  --exclude=test/*.apk --exclude=test/temp/* --exclude=test/*.sis
test/
test/temp/
test/make.sh
test/package.jar
test/android.php
test/head.php
test/test.php
test/make.sh.bk
test/make.php
test/source_id.txt
test/index.php
test/index.php.bkkkk
test/KingGoo.Com.sh
test/bak/
test/index.php.bk
test/symbian.php
test/debug/
test/index.php.bkk
test/index1.php
test/index.php.bkkk
test/androidpad.php
test/lingxa

查看一下,壓縮包內的文件(非解壓)

[root@**** html]# tar  -tf  test.tar.gz 
test/
test/temp/
test/make.sh
test/package.jar
test/android.php
test/head.php
test/test.php
test/make.sh.bk
test/make.php
test/source_id.txt
test/index.php
test/index.php.bkkkk
test/KingGoo.Com.sh
test/bak/
test/index.php.bk
test/symbian.php
test/debug/
test/index.php.bkk
test/index1.php
test/index.php.bkkk
test/androidpad.php
test/lingxa

版權聲明:

轉載原創文章請注明,文章出處: http://kinggoo.com
原文地址: http://kinggoo.com/linux-tarexlude.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM