How to check if a symlink exists

前端 未结 8 2078
無奈伤痛
無奈伤痛 2020-12-04 05:04

I\'m trying to check if a symlink exists in bash. Here\'s what I\'ve tried.

mda=/usr/mda
if [ ! -L $mda ]; then
  echo \"=> File doesn\'t exist\"
fi


mda         


        
8条回答
  •  一向
    一向 (楼主)
    2020-12-04 05:48

    Maybe this is what you are looking for. To check if a file exist and is not a link.

    Try this command:

    file="/usr/mda" 
    [ -f $file ] && [ ! -L $file ] && echo "$file exists and is not a symlink"
    

提交回复
热议问题