从查找中排除目录列表

Ric*_*ard 5 linux command-line find

我正在使用 rsynccrypto 备份一些用户目录。我想从加密中排除一些子目录。我读到,执行此操作的最佳方法是将 find 的输出通过管道传输到 rsynccrypto。

这是一个排除名为 tmp 的目录的 find 命令:

find ~/Documents -type d -not \( -name tmp -prune \)
Run Code Online (Sandbox Code Playgroud)

我有六七个这样的目录需要排除。有没有一种简单的方法可以让我在 find 命令中枚举所有这些?

Den*_*son 0

您可以使用正则表达式:

find ~/Documents -type d ! \( -regex '.*/\(foo\|bar\|baz\)/?$' -prune \)
Run Code Online (Sandbox Code Playgroud)

请记住,正则表达式匹配整个目录/文件结构,而不仅仅是基本名称。