Check directory is mounted

To check that a directory is mounted in a bash script:

echo "Mounting /mnt/share..."
sudo mount /mnt/share

if ! mount | grep '/mnt/share ' > /dev/null; then
  echo "/mnt/share not mounted. Exiting."
  exit
fi

# Do stuff with /mnt/share

echo "Unmounting /mnt/share..."
sudo umount /mnt/share

if mount | grep '/mnt/share ' > /dev/null; then
  echo "/mnt/share not unmounted"
fi

Reference: Check if directory mounted with bash

Last modified: 27/11/2016 Tags:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top