Suppose do you want test if /mnt/disk is a mount point in a shell script. How do you do this?
Not relying on mount
, /etc/mtab
, /proc/mounts
, etc.:
if [ `stat -c%d "$dir"` != `stat -c%d "$dir/.."` ]; then
echo "$dir is mounted"
else
echo "$dir is not mounted"
fi
When $dir
is a mount point, it has a different device number than its parent directory.
The benefit over the alternatives listed so far is that you don't have to parse anything, and it does the right thing if dir=/some//path/../with///extra/components
.
The downside is that it doesn't mark /
as a mountpoint. Well, that's easy enough to special-case, but still.