最近有人問我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