尝试
find * -maxdepth 0 -name "efence*" -prune -o -print
如果没有指定其他选项,则prune选项会打印匹配文件(但是仍然会阻止find递归到匹配的目录中).
编辑添加说明:
查找表达式区分测试和操作.从男人发现:
The expression is made up of options (which affect overall operation
rather than the processing of a specific file, and always return true),
tests (which return a true or false value), and actions (which have
side effects and return a true or false value), all separated by operators. -and is assumed where the operator is omitted.
If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true. [my emphasis]
所以-prune是一个具有副作用的动作,它不会递归到与前面测试相匹配的子目录(在你的例子中,-maxdepth 0 -name“efence *”).但就表达式的真值而言,它只相当于拥有
find * -maxdepth 0 -name "efence*" -true
并且由于您没有指定任何其他操作,因此假定-print(此假设始终存在,因为它允许您键入例如find.-name“* .java”而不是find.-name“* .java”-print ).
希望有道理.在the other thread接受的答案谈到了同样的事情.