Linux Filesystem Mount

mountpoint — check if a directory is a mount point

mountpoint tests whether a given directory is a mount point and returns an appropriate exit status.

What mountpoint is good for

Use exit codes in scripts rather than parsing mount output manually.

10 Practical Examples

1) Check if directory is a mount point

mountpoint /mnt/data

2) Silent mode (for scripting)

mountpoint -q /mnt/data

3) Check exit status

mountpoint -q /mnt/data
echo $?

0 = is mount point, 1 = not mount point

4) Use in shell conditional

if mountpoint -q /mnt/data; then
    echo "Mounted"
else
    echo "Not mounted"
fi

5) Validate before unmount

if mountpoint -q /mnt/data; then
    sudo umount /mnt/data
fi

6) Check multiple directories

for d in /mnt/*; do
    mountpoint -q "$d" && echo "$d is mounted"
done

7) Compare with findmnt

findmnt /mnt/data
mountpoint /mnt/data

8) Check root mount

mountpoint /

9) Verbose output

mountpoint /mnt/data

Outputs message indicating mount status.

10) Use in backup script

if mountpoint -q /backup; then
    rsync -av /data/ /backup/
else
    echo "Backup drive not mounted!"
fi