最近有人问我tar压缩能不能不包含不想要的文件或者文件夹 压缩包很利于传送,备份等等。但比如大量的日志文件一般是不需要备份,或者需要分开备份。 tar参数中的–exclude,这个是我在看鸟哥私房菜时看到的。当时觉得肯定有用,就多留意了几眼,但使用的时候发现不是那么回事,所以后来就多研究了一下。没想到现在对于备份来说很舒服~~~得心应手,如果要包含其他路径的文件需要使用–include 例子: 在我的test文件夹下面,包含一些symbian的sisx安装包及andoid包apk安装包等等 test的大致目录结构:
[root@**** html]# tree -L 2 testtest|--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.php8 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/*.sistest/test/temp/test/make.shtest/package.jartest/android.phptest/head.phptest/test.phptest/make.sh.bktest/make.phptest/source_id.txttest/index.phptest/index.php.bkkkktest/KingGoo.Com.shtest/bak/test/index.php.bktest/symbian.phptest/debug/test/index.php.bkktest/index1.phptest/index.php.bkkktest/androidpad.phptest/lingxa
查看一下,压缩包内的文件(非解压)
[root@**** html]# tar -tf test.tar.gz test/test/temp/test/make.shtest/package.jartest/android.phptest/head.phptest/test.phptest/make.sh.bktest/make.phptest/source_id.txttest/index.phptest/index.php.bkkkktest/KingGoo.Com.shtest/bak/test/index.php.bktest/symbian.phptest/debug/test/index.php.bkktest/index1.phptest/index.php.bkkktest/androidpad.phptest/lingxa