0

rsync我可以在一个数组中定义我的排除/选项并在后续命令中使用这些数组,例如

rsync "${rsyncOptions[@]}" "${rsyncExclusions[@]}" src dest

我想使用该find命令实现相同的目的,但找不到使其工作的方法:

findExclusions=(
    "-not \( -name '#recycle' -prune \)"
    "-not \( -name '#snapshot' -prune \)"
    "-not \( -name '@eaDir' -prune \)"
    "-not \( -name '.TemporaryItems' -prune \)"
)
LC_ALL=C /bin/find src -mindepth 1 "${findExclusions[@]}" -print

在我尝试定义数组的任何组合中(单引号与双引号,转义括号)我总是以错误告终:

find: unknown predicate `-not \( -name '#recycle' -prune \)'
# or
find: paths must precede expression: ! \( -name '#recycle' -prune \)

这样做的正确方法是什么?

4

1 回答 1

4

这里的问题"-not \( -name '#recycle' -prune \)"是不是一个论点,而是六个论点。你可以这样写:

findExclusions=(
    -not '(' -name '#recycle' -prune ')'
    -not '(' -name '#snapshot' -prune ')'
)
于 2019-01-19T07:40:00.230 回答