Linux – Check if something is mounted


I want to check if something is mounted or not in /mnt/MyCloud. I tried:

  • if mountpoint -q /mnt/MyCloud; then
  • if mountpoint -q "/mnt/MyCloud"; then
  • Edit: if mount | grep /mnt/MyCloud > /dev/null; then

Both go to else (returns false I guess)

What is the proper way to check such thing?

Best Answer

As per the mountpoint man page:


Zero if the directory or file is a mountpoint, non-zero if not.

By your snippet I'd say the check is done correctly. Furthermore, I tried it with a mountpoint of mine and it returns what is expected.


if mountpoint -q /home; then
  echo "It's a mountpoint"

When run, the code prints the phrase. If you're not getting this behavior, I'd:

  • Check if the package that contains mountpoint is corrupt.
  • Check the man page of your command. The return code might differ between different distributions.
  • Check if it's actually a mountpoint. You can run a bare mount command and check if it's listed among the currently mounted points. Note that a non-mounted point will return a non-zero code as per the documentation, even if the directory/file exists.
Related Question