> Linux命令 >

tar压缩时排除指定目录的方法

tar压缩文件时排除指定目录的方法。

假设 test目录下有 1 2 3 4 5 这5个目录,现在要将 3 4 5目录tar打包,1和2目录不要。

命令:
 

tar -zcvf test.tar.gz --exclude=1 --exclude=2 test

tar -zcvf test.tar.gz --exclude=test/1 --exclude=test/2 test

看man tar帮助,--exclude后面跟的好像是正则。

注意: 要打包的test必须在命令最后。




(责任编辑:IT)