使用find搜索*.js文件时,如何排除特定目录?
find . -name '*.js'
使用find搜索*.js文件时,如何排除特定目录?
find . -name '*.js'
当前回答
如果您正在寻找一个高性能的答案,那么它就是:
find . -type d -name node_modules -prune -false -o -type f
使用-false排除node_modules本身。
在node_modules中包含10000个文件的目录中,它将比非路径方法快3倍。
find . -type f -not -path '*node_modules*'
如果node_modules有更多的文件,您将获得更高的性能。
其他回答
如果您正在寻找一个高性能的答案,那么它就是:
find . -type d -name node_modules -prune -false -o -type f
使用-false排除node_modules本身。
在node_modules中包含10000个文件的目录中,它将比非路径方法快3倍。
find . -type f -not -path '*node_modules*'
如果node_modules有更多的文件,您将获得更高的性能。
find -name '*.js' -not -path './node_modules/*' -not -path './vendor/*'
似乎与
find -name '*.js' -not \( -path './node_modules/*' -o -path './vendor/*' \)
并且更容易记住IMO。
这适合我在Mac上使用:
find . -name *.php -or -path "./vendor" -prune -or -path "./app/cache" -prune
它将排除带有php后缀的搜索名称的供应商和app/cache-dir。
以下命令有效:
find . -path ./.git -prune -o -print
如果查找有问题,请使用-D树选项查看表达式分析信息。
find -D tree . -path ./.git -prune -o -print
或者使用-D all,查看所有执行信息。
find -D all . -path ./.git -prune -o -print
对于FreeBSD用户:
find . -name '*.js' -not -path '*exclude/this/dir*'