find中的-prune选项有什么作用? [英] What does -prune option in find do?
问题描述
我可以看到 find
的-prune无法正常工作。我想 -nameefence *-prune
选项应选择(或查找)除名称 efence *
对吗?
或者我的理解错了吗?
我执行的命令是:
find * -maxdepth 0 -nameefence *-prune
期望 :选择当前目录中的所有文件( maxdepth 0
),除了名称* efence。
请帮我了解 -prune
find * -maxdepth 0 -nameefence *-prune -o -print
编辑添加解释: 表达式由选项组成操作 如果表达式不包含除<在表达式为真的所有文件上执行code> -prune
如果没有指定其他选项,则 prune
选项不会打印匹配的文件但是) find 从递归到匹配的目录中找到
,
find
表达式区分 tests
和动作
。从 man找到
:
,而不是处理一个特定的文件,并且总是返回true),
tests(返回true或者false的值)和action(具有
的副作用并且返回true或虚假值),全部由运营商分隔。
-print
。
所以 -prune
是一个副作用是 find
不会递归到与前面的测试相匹配的子目录中(在您的情况下, -maxdepth 0 -nameefence *
) 。但是就表达式的真值而言,它相当于只有
find * -maxdepth 0 -nameefence *-true
由于您没有指定任何其他操作,所以 -print
是假定的(这个假设总是存在的,因为它允许你输入例如 find。-name* .java
而不是 find。-name* .java-print
)。
希望是有道理的。在另一个线程接受的答案谈论同样的事情。
I can see the -prune of find
not working correctly. I guess -name "efence*" -prune
option should select (or find) all files except the one with name efence*
right?
Or am i wrong in my understanding?
The command i executed:
find * -maxdepth 0 -name "efence*" -prune
Expectation: Select all files at current directory (maxdepth 0
) except one with name *efence.
Please help me to understand -prune
Try
find * -maxdepth 0 -name "efence*" -prune -o -print
The prune
option does print matching files, if no other options are specified (it still prevents find
from recursing into matching directories, however).
Edited to add explanation:
find
expressions distinguish between tests
and actions
. From man 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
,
So -prune
is an action which has the side effect that find
will not recurse into subdirectories which match the preceding test (in your case, -maxdepth 0 -name "efence*"
). But in terms of the truth-value of the expression, it's equivalent to just having
find * -maxdepth 0 -name "efence*" -true
and since you didn't specify any other action, -print
is assumed (this assumption is always present as it allows you to type e.g. find . -name "*.java"
instead of find . -name "*.java" -print
).
Hope that makes sense. The accepted answer at the other thread talks about the same thing.
这篇关于find中的-prune选项有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!