Linux中find命令的prune参数探究
记得很久之前找过prune的参数使用,应急用了之后没有记录,但过了一段时间就会忘记,这次趁机找了一圈,包括Google-aosp里面的用法也对比参照了一下。
参考 https://www.jianshu.com/p/e0a9fb35601a
发现描述基本没问题,使用上还有些差异,特此记录一下:
<以下主要是 -prune -o -print 三者叠加情况的过滤实践 >
test-1:
date; mx=2; find . -maxdepth $mx -type d -path "./.git" -prune -o -path "./.repo" -prune -o -path "./out" -prune -o -type f -name "*akefile*" -print
2023年 09月 20日 星期三 13:34:05 CST
./kernel/Makefile
./u-boot/Makefile
./Makefile
test-2:
$ date; mx=2; find . -maxdepth $mx -type d -path "./.git" -prune -o -path "./.repo" -prune -o -path "./out" -prune -o -wholename "./Makefile" -prune -o -type f -name "*akefile*" -print
2023年 09月 20日 星期三 13:36:21 CST
./kernel/Makefile
./u-boot/Makefile
test-3:
$ date; ex=;mx=2; find . -maxdepth $mx -type d -path "./.git" -prune -o -path "./.repo" -prune -o -path "./out" -prune -o -wholename "./Makefile" -prune -o -type f -name "*akefile*"
2023年 09月 20日 星期三 13:37:15 CST
./kernel/Makefile
./out
./u-boot/Makefile
./Makefile
./.git
PS: -o 理论上和shell的或符号'||'等价,但又不太一致,它在find的输出中也有与的成分存在,后面有print参数存在时会优先被print与掉,否则依旧会跳过prune的原意来输出!
应该是内部有优先权重在匹配,有空得去看看find的源码是如何实现的。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通