我可以看到-prune找不到正常工作.我猜-name“efence *”-prune选项应该选择(或找到)除了名称为efence *的文件之外的所有文件?
或者我的理解是错的?
我执行的命令:
找* -maxdepth 0 -name“efence *”-prune
期望:选择当前目录(maxdepth 0)中的所有文件,但名称为* efence的文件除外.
请帮我理解-prune
解决方法:
尝试
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接受的答案谈到了同样的事情.
标签:linux,find
来源: https://codeday.me/bug/20190614/1236338.html