LinuxCommandLibrary

mountpoint

Check if a directory is a mountpoint

TLDR

Check if a directory is a mountpoint

$ mountpoint [path/to/directory]
copy

Check if a directory is a mountpoint without showing any output
$ mountpoint [[-q|--quiet]] [path/to/directory]
copy

Show major/minor numbers of a mountpoint's filesystem
$ mountpoint [[-d|--fs-devno]] [path/to/directory]
copy

SYNOPSIS

mountpoint [-dnq] [-x|--xml] directory...

PARAMETERS

-d
    Reports only device name for the mount point. The device name will be printed on standard output.

-n
    Don't consult /etc/mtab. This is useful if you want to know about mount points other than those in the current namespace or while in a mount namespace where /etc/mtab is not available. It always consults /proc/mounts to find all mount points.

-q
    Be quiet; return 0 if directory is a mountpoint; non-zero if not. Suppress all output.

-x, --xml
    Output in XML format. For each mount point, the device, mount point, and mount options are displayed.

directory...
    One or more directory paths to be checked. If a directory is a mountpoint, its path is printed.

DESCRIPTION

The mountpoint command in Linux is used to determine if a directory is a mount point. It checks if the specified directory is the root directory of a mounted filesystem. If it is, mountpoint prints the path of the directory; otherwise, it outputs that the directory is not a mount point.
This tool is useful for scripting and automation where you need to programmatically identify mount points within a system. It's a straightforward way to verify the mount status of a directory and can be integrated into system monitoring scripts or installation procedures to confirm that filesystems are mounted as expected before proceeding with operations.
The command analyzes the /proc/mounts file (or the mtab file on some systems) to determine if the target directory is a mount point. It offers options to check if the mount is a bind mount, a shared mount, or if the mount point is propagated to a specific peer group.

CAVEATS

The accuracy of the mountpoint command depends on the availability and consistency of the information in /proc/mounts or /etc/mtab. If these files are outdated or inaccurate, the command may provide incorrect results. Root privileges might be needed to access certain mount information.

EXIT STATUS

The mountpoint command returns 0 if the specified directory is a mount point and a non-zero value otherwise.

BIND MOUNTS

The command can identify bind mounts, which are a way to make a directory or file accessible at another location in the filesystem. Bind mounts are identified based on the mount options.

HISTORY

The mountpoint command has been a standard utility in Unix-like operating systems for many years. Its purpose is to provide a simple and reliable way to determine the mount status of a directory. It has evolved with the Linux kernel, adapting to changes in mount namespace and the way mount information is stored and accessed. The XML output option was added in later versions to facilitate machine parsing of mount information.

SEE ALSO

mount(8), umount(8), findmnt(1)

Copied to clipboard