查找但不下降到包含搜索文件的目录 [英] Find but do not descend into directories containing the searched files
问题描述
我有几个项目由pom.xml或类似的配置。
我想使用linux file命令找到这些项目,例如通过查找-name pom.xml
。
然而,由于深度路径,这需要一些时间。我希望使用 find -prune
来停止在子目录中搜索,当我已经找到文件时,剪切只停留在匹配的目录上,而不是在匹配的文件上。 b
$ b
有没有一种方法可以在目录中包含搜索文件时停止下降?
澄清;这是我没有找到:
pfind(){
parent = $ 1&&将$ @中的文件转换为
; do
path = $ parent / $ file
if [-e$ path];然后
echo$ path
exit 0
fi
done
for $(echo $ parent / *)中的dir做
if [-d$ dir];然后
pfind$ dir$ @
fi
完成
}
但是我宁愿使用一个简单的方法来查找,所以对其他人来说可以更容易理解/扩展
find。 -name pom.xml -print -quit
如果要加快搜索速度,也可以使用 locate
来查找数据库,而不是扫描文件系统。
您可以通过运行 updatedb
来更新数据库
I have several projects configured by a pom.xml or similar.
I would like to use the linux file command to locate these projects e.g. by find -name pom.xml
.
This however takes some time because of the deep paths. I would like to use find -prune
to stop searching in subdirectories when I already find the file, but prune only stops on matched directories not on matched files.
Is there a way to get find to stop descending when the directory aleady contains a searched file?
For clarification; this is what I do without find:
pfind() {
parent=$1 && shift
for file in "$@" ; do
path=$parent/$file
if [ -e "$path" ] ; then
echo "$path"
exit 0
fi
done
for dir in $(echo $parent/*) ; do
if [ -d "$dir" ] ; then
pfind "$dir" "$@"
fi
done
}
But I'd rather use a simple way with find so it is better understandable/extendable for others
find . -name pom.xml -print -quit
If you want to speed up the search, you can also work with locate
, which queries a database instead of scanning the file system.
You can update the database using by running updatedb
这篇关于查找但不下降到包含搜索文件的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!