我有以下目录结构:
test/
test/1/
test/foo2bar/
test/3/
Run Code Online (Sandbox Code Playgroud)
我想压缩目录“test”,不包括子目录中的所有内容(深度未预定义),其中包括字符串“1”或“2”。在 bash shell 中,我想使用find并将其输出提供给tar。我首先测试发现:
find test/ -not -path "*1*" -not -path "*2*"
Run Code Online (Sandbox Code Playgroud)
输出:
test/
test/3
Run Code Online (Sandbox Code Playgroud)
伟大的。所以我将它与tar结合起来:
find test/ -not -path "*1*" -not -path "*2*" | tar -czvf test.tar.gz --files-from -
Run Code Online (Sandbox Code Playgroud)
输出:
test/
test/3/
test/1/
test/foo2bar/
test/3/
Run Code Online (Sandbox Code Playgroud)
事实上,“test/1”和“test/foo2bar”都存在于档案中。如果这些参数不应该出现在 find 输出中,为什么要传递给 tar?