I have a tmpfs file system mounted on a particular directory. I want to write a shell script to check whether the tmpfs filesystem is already mounted on the directory.
There's a tool specifically for this: mountpoint(1)
if mountpoint -q "$directory" ; then
echo it is a mounted mountpoint
else
echo it is not a mounted mountpoint
fi
And you don't even have to scrape strings to do it!
Note that I find this tool in Debian's initscripts package. How available it is elsewhere is not something I can comment on.
You can check the type of the filesystem.
$ stat -f -c '%T' / xfs $ stat -f -c '%T' /dev/shm tmpfs
You could also check whether a directory is a mountpoint by comparing its device with its parent's.
$ stat -c '%D' / 901 $ stat -c '%D' /home fe01 $ stat -c '%D' /home/$USER fe01
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With