并不只是 print 位置不对的问题,你如果执行 find ./ -type d -print -name ‘.git’ -exec echo Matched {} + 就会有所发现。
因为上面这条命令等价于 find ./ ( -type d -and -print -and -name ‘.git’ ) -exec echo Matched {} +
而在-print 的文档中就说明了,这个“条件”总是为 true,并打印“当前”文件的 pathname 到 stdout 。( This primary always evaluates to true. It prints the pathname of the current file to standard output.)
不知道为什么主会去单用 print 这个选项。因为 print 这个选项还说:假如”-exec, -ls, -print, -print0, -ok”没有任何一个被使用,那么命令会默认最后加一个-print ( If none of -exec, -ls, -print, -print0, or -ok is specified, the given expression shall be effectively replaced by ( given expression ) -print.)
说 find 是上古东西的当然可以自己写脚本来做嘛,python 一个 os.walk 也不费什么劲。像 find 这种东西一些过时设计已经没法改了,因为肯定有大量的运维脚本依赖于这个“错误”设计。但是对于熟悉的人来说,写这么一段命令肯定比写脚本快得多。