简体   繁体   中英

Using find command in Bash script and excluding the subdirs

I wrote some function that should find a directory inside a parent directory, but the thing is that it's taking to long, probably it's searching in the subdirectories as well. Here is my code:

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"
}

I know for sure that the directory that i'm looking for is under /opt/SwDrop/Repository/ and it can't be in the subdirectories. Any idea how to solve it ?

-maxdepth 1向您的find命令添加-maxdepth 1 (请参阅GNU Findutils )。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM