在查找命令中排除子路径

Exclude a subpath in find command

我有以下 find 命令:

find /mnt/F_11 -type f \( -iname '*.xls' -o -iname '*.xlsx' /)

如何找到 /mnt/F_11 中但不在 /mnt/f_11/DONOTENTER/ 中的所有项目?

换句话说,我希望它搜索:

YES /mnt/F_11
YES /mnt/F_11/somepath/
YES /mnt/F_11/somepath/other/
NO  /mtn/F_11/DONOTENTER/

使用 -prune 避免递归到您不想遵循的分支。

find /mnt/F_11 -name DONOTENTER -prune -o \
     -type f \( -iname '*.xls' -o -iname '*.xlsx' \) -print

注意末尾的显式 -print -- 这很重要,否则隐式打印操作会覆盖两个分支。