[英]Using find command in Bash script and excluding the subdirs
我写了一些函数,应该在父目录中找到一个目录,但事实是它要花很长时间,可能也在子目录中搜索。 这是我的代码:
function findMspDir () {
mountedDir=/opt/SwDrop/
dirToSearch=/opt/SwDrop/Repository/
if [ ! -d $mountedDir ]; then
echo "The directory hasn't been found"
exit 1;
else
echo "The directory is mounted"
subDirToSearch="MSP-$versionNum"
# mspDir=`find $dirToSearch -name $subDirToSearch`
mspDir=$(find /opt/SwDrop/Repository/ -name 'MSP-1.5.1.4')
if [ "$mspDir" = "" ]; then
echo "The MSP directory hasn't been found"
exit 1;
fi
fi
echo "The found directory is: $mspDir"
}
我肯定知道我要查找的目录在/opt/SwDrop/Repository/
,并且不能在子目录中。 知道如何解决吗?
-maxdepth 1
向您的find命令添加-maxdepth 1
(请参阅GNU Findutils )。
find -maxdepth 1 -name "you_name" -a type d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.