find 中的 -prune 选项有什么作用?
我可以看到 find
的 -prune 无法正常工作。我想 -name "efence*" -prune
选项应该选择(或查找)除了名称为 efence*
的文件之外的所有文件,对吗?
还是我的理解有误?
我执行的命令: find * -maxdepth 0 -name "efence*" -prune
期望:选择当前目录下的所有文件 (maxdepth 0
),除了带有 name 的文件*围栏。
请帮助我理解 -prune
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有指定其他选项,请尝试
prune 选项确实打印匹配的文件(但是,它仍然会阻止
find
递归到匹配目录)。编辑添加解释:
find
表达式区分tests
和actions
。来自man find
:因此
-prune
是一个具有副作用的操作,find
不会递归到与前面的测试匹配的子目录(在您的情况下,-maxdepth 0 -name “围栏*”
)。但就表达式的真值而言,它相当于仅具有并且由于您没有指定任何其他操作,因此假定
-print
(此假设始终存在,因为它允许您键入例如find .name "*.java"
而不是find -name "*.java" -print 。
希望这是有道理的。 另一个线程中接受的答案讨论了同样的事情。
Try
The
prune
option does print matching files, if no other options are specified (it still preventsfind
from recursing into matching directories, however).Edited to add explanation:
find
expressions distinguish betweentests
andactions
. Fromman find
:So
-prune
is an action which has the side effect thatfind
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 havingand 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 offind . -name "*.java" -print
).Hope that makes sense. The accepted answer at the other thread talks about the same thing.