Linux 在Bash脚本中使用find命令并排除子曲面

Linux 在Bash脚本中使用find命令并排除子曲面,linux,bash,shell,unix,gnu-findutils,Linux,Bash,Shell,Unix,Gnu Findutils,我写了一些应该在父目录中查找目录的函数,但问题是它需要很长时间,可能它也在子目录中搜索。 这是我的密码: function findMspDir () { mountedDir=/opt/SwDrop/ dirToSearch=/opt/SwDrop/Repository/ if [ ! -d $mountedDir ]; then echo "The directory hasn't been found" exit 1; el

我写了一些应该在父目录中查找目录的函数,但问题是它需要很长时间,可能它也在子目录中搜索。 这是我的密码:

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/
下,它不能位于子目录中。
你知道怎么解决吗?

可以在find命令中添加
-maxdepth 1
(请参阅)。

可以在find命令中添加
-maxdepth 1

查找-maxdepth 1-名称“you\u name”-a类型d
查找-maxdepth 1-名称“you\u name”-类型d

什么是
-a
代表什么?逻辑“和”是-a,逻辑“或”是-o,这是一种将多个条件组合在一个中的方式。
-a
代表什么?逻辑“和”是-a,逻辑“或”是-o,这是一种将多个条件组合在一个中的方式。