How to check whether or not a particular directory is a mount point?
For instance there is a folder named /test
that exists, and I want to check if it is a mount point or not.
6 Answers
If you want to check it's the mount point of a file system, that's what the mountpoint
command (on most Linux-based systems) is for:
if mountpoint -q -- "$dir"; then
printf '%s\n' "$dir is a mount point"
fi
It does that by checking whether .
and ..
have the same device number (st_dev
in stat()
result). So if you don't have the mountpoint
command, you could do:
perl -le '$dir = shift; exit(1) unless
(@a = stat "$dir/." and @b = stat "$dir/.." and
($a[0] != $b[0] || $a[1] == $b[1]))' "$dir"
Like mountpoint
, it will return true for /
even if /
is not a mount point (like when in a chroot
jail), or false
for a mount point of a bind mount of the same file system within itself.
Contrary to mountpoint
, for symbolic links, it will check whether the target of the symlink is a mountpoint.

- 544,893
-
1At least on Ubuntu, the output of mountpoint already says "$dir is a mountpoint" ,so you don't need the if part around it. – Sergiy Kolodyazhnyy Sep 17 '16 at 09:49
-
@SergiyKolodyazhnyy the -q means quiet output, so in this case, the output is being suppressed and then replaced by custom output. Unnecessary, but yeah. – Wyrmwood Jul 25 '17 at 19:49
-
@Wyrmwood I know what the options are. What I'm saying is that
mountpoint "$dir"
already does exactly the same as the 3-line if statement does here. Functionally they're the same. Such use ofmountpoint -q
inif
statement can be used when you want to perform some action based on the exit status, but for printing the message to user its unnecessary - it's already the default behavior of the program. – Sergiy Kolodyazhnyy Jul 25 '17 at 20:21 -
How can I install
mountpoint
into macOS? I have tried through brew but system is unable to see it – alper Apr 14 '22 at 12:35
As HalosGhost mentions in the comments, directories aren't necessarily mounted per se. Rather they're present on a device which has been mounted. To check for this you can use the df
command like so:
$ df -h /boot/
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 99M 55M 40M 59% /boot
Here we can see that the directory /boot
is part of the filesystem, /dev/hda1
. This is a physical device, on the system, a HDD.
You can also come at this a little bit differently by using the mount
command to query the system to see what devices are currently mounted:
$ mount | column -t
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/mapper/lvm--raid-lvm0 on /export/raid1 type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
Here you can see the type of device and the type of filesystems are currently mounted on your system. The 3rd column shows where they're mounted on the system within its filesystem.

- 369,824
-
3To check if a particular directory is an active mountpoint (especially in scripts, where a binary result is handy), the
mountpoint
command is a nice alternative e.g.if mountpoint -q /path/to/dir; then ...
. I'm not sure how widely available it is though. – steeldriver Aug 21 '14 at 14:14 -
@steeldriver - cool, never seen that one before. It's present on my Red Hat distros. – slm Aug 21 '14 at 14:20
-
@slm: Am I going blind, or was your cat walking on your keyboard when you posted this answer? It says, “Here we can see that the directory
/usr
is part of the filesystem, …”, but/usr
appears nowhere else in the answer. – G-Man Says 'Reinstate Monica' Dec 06 '15 at 23:54 -
@G-Man - I meant to type /boot there, I fixed it. Given the above example shows /boot it seemed pretty obvious what I meant when I typed that, even with the typo. – slm Dec 07 '15 at 03:17
-
Why not just
mounpoint $(pwd)
? It prints/jail/bin is a mountpoint
. Btw, I thinkfindmnt
of @xharx 's answer is the best. – Rick May 25 '22 at 07:16
I was looking for the same question when I wanted to check mounting a new XFS filesystem.
I found the command findmnt: findmnt /directoryname
[root@CentOS7-Server /]# findmnt /mnt
TARGET SOURCE FSTYPE OPTIONS
/mnt /dev/sdb1 xfs rw,relatime,seclabel,attr2,inode64,noquota
[root@CentOS7-Server /]#
-
-
This is the best.
findmnt
gives the most informative output compared to some others. That is, it tells which specific diretory is the target mounted from. One can runfindmnt
with no arguments. – Rick May 25 '22 at 07:15
Well, as others said you should edit your question and make it clear on what you are trying to achieve. As far as I understood, you need to check if a directory is mounted to a particular device. You can try something like below as well.
df -P /test | tail -1 | cut -d' ' -f 1
So basically, the above command lets you know the mount point of the directory if at all the device is mounted to a directory.

- 39,297
Nice and short Python one-liner can be constructed based on Gilles' answer:
$ python -c 'import os,sys;print(os.path.ismount(sys.argv[1]))' /mnt/HDD
True
$ python -c 'import os,sys;print(os.path.ismount(sys.argv[1]))' /etc
False
I've made custom implementation of mountpoint
command in Python, which parses /proc/self/mounts
file. Kind of the same behavior as mount
in Stephane's answer, except that command parses /proc/self/mountinfo
. Usage is very simple: is_mountpoint.py /path/to/dir
.
#!/usr/bin/env python3
from os import path
import sys
def main():
if not sys.argv[1]:
print('Missing a path')
sys.exit(1)
full_path = path.realpath(sys.argv[1])
with open('/proc/self/mounts') as mounts:
print
for line in mounts:
if full_path in line:
print(full_path,' is mountpoint')
sys.exit(0)
print(full_path,' is not a mountpoint')
sys.exit(1)
if __name__ == '__main__':
main()
Test run:
$ python3 ./is_mountpoint.py /mnt/HDD
/mnt/HDD is mountpoint
$ lsblk | grep HDD
└─sdb6 8:22 0 405.3G 0 part /mnt/HDD
$ python3 ./is_mountpoint.py $HOME
/home/xieerqi is not a mountpoint

- 16,527
Your question is little bit confusing, but I guess, one of the ways to check that: mount |awk '{print $3}'| grep -w <your_directory>
. If output is empty then no device mounted to the directory . If not empty then some device mounted to the directory. Other way is to use df <your_directory>
. If last field equals to your directory name - than some device is mounted to it.

- 2,397
mount
directories on Linux. Youmount
devices to particular directories. Checking to see if something is mounted is as simple as looking at the output of themount
command. – HalosGhost Aug 21 '14 at 14:01NOTMOUNTED
. When you can see the file, the directory is not a mount point, and when you don't, it is. – Mark Plotnick Aug 21 '14 at 14:13