tar 排除指定目录 –exclude

假设 test目录下有 1 2 3 4 5 这5个目录,

1下有6 7两个目录,

现在要将3 4 5 6目录tar打包,2和1下的6这两个目录不要.
命令如下:

Example
[www]#cd test
[test]#tar -zcvf test.tar.gz --exclude=1/6 --exclude=2 test


Example
[www]#tar -zcvf test.tar.gz --exclude=test/1/6 --exclude=test/2 test
查看 tar –help 帮助,–exclude后面跟的是通配符或者正则表达式。这个功能也很强大,不是么。例如想排除1文件夹下的所有.log文件,那就可以这样子:
通配符:

Example
[www]#tar -zcvf test.tar.gz --exclude=test/1/*.log test
正则:

Example
[www]#tar -zcvf test.tar.gz --exclude=/test/1/.*log/ test
注意: 要打包的test文件夹或文件必须在命令最后,否则不会生效。

转载 http://digdeeply.org/archives/11271575.html

原文地址:https://www.cnblogs.com/jackspider/p/4039445.html