加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – find中的-prune选项有什么作用?

发布时间:2020-12-13 23:50:01 所属栏目:Linux 来源:网络整理
导读:我可以看到-prune找不到正常工作.我猜-name“efence *”-prune选项应该选择(或找到)除了名称为efence *的文件之外的所有文件? 或者我的理解是错的? 我执行的命令: ?找* -maxdepth 0 -name“efence *”-prune 期望:选择当前目录(maxdepth 0)中的所有文件,
我可以看到-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接受的答案谈到了同样的事情.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读