有什么不对的tar命令?焦油排除没有工作
$ tar --exclude='/tmp/test/exclude-me' -zcvf test.tar.gz test
test/
test/c.txt
test/exclude-me/
test/exclude-me/b.txt
test/a.txt
正如您所见,exclude-me
在我解压归档时存在。我也试过--exclude=/tmp/test/exclude-me/*
。
有什么不对的tar命令?焦油排除没有工作
$ tar --exclude='/tmp/test/exclude-me' -zcvf test.tar.gz test
test/
test/c.txt
test/exclude-me/
test/exclude-me/b.txt
test/a.txt
正如您所见,exclude-me
在我解压归档时存在。我也试过--exclude=/tmp/test/exclude-me/*
。
exclude
系列参数适用于内部相对 tarball中文件的名称。您指定的绝对路径将永远不会存在于tarball中,因为它只有来自提供的根的相对路径。
你必须省略路径的绝对部分。
在您的例子中,你使用V标志和所包含的文件中列出。
的排除模式是根据该列表中的条目匹配,而不是实际的文件路径。所以你必须改变你的模式来“测试/排除我”。
出于某种原因,你还必须删除尾随/的文件夹。
谢谢!这工作,但我仍然有一个棘手的排除情况:我的档案扎根于'a',我想排除'a/b',但我想保留'a/a/b'。那可能吗? – 2014-09-03 22:56:19
对于更复杂的场景,您可以首先将'find'运行到'排除文件',然后用'--exclude-from'包含它。 [全部选项列表](http://www.gnu.org/software/tar/manual/html_node/exclude.html#SEC109)。 – 2014-09-03 23:06:25
除非使用'--no-achored'选项,否则排除模式必须与文件名的开头匹配。 – 2014-09-04 00:24:53