0

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

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/其下且不能位于子目录中。知道如何解决吗?

4

2 回答 2

3

随意添加-maxdepth 1到您的 find 命令中(参见GNU Findutils)。

于 2014-09-28T11:55:30.460 回答
1

find -maxdepth 1 -name "you_name" -a type d

于 2014-09-28T12:19:20.817 回答