[英]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.