gpt4 book ai didi

linux - 在 Bash 脚本中使用 find 命令并排除子目录

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:58:07 36 4
gpt4 key购买 nike

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

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 添加到您的查找命令(参见 GNU Findutils )。

关于linux - 在 Bash 脚本中使用 find 命令并排除子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26084582/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com