Bash script: effectively check if a filesystem is mounted

Whenever you want to check if a file system is mounted and perform some action in you script based on this, the simplest and most accurate way to do it in Linux is to check /proc/mounts:

if grep -qs ‘/mnt/sda2′ /proc/mounts; then
echo “fs mounted”
else
echo “fs not mounted”
fi

Leave a Reply

You must be logged in to post a comment.