How to use the command mountpoint (with examples)
- Linux
- December 25, 2023
The mountpoint
command is used to test if a directory is a filesystem mountpoint. It provides a simple way to determine whether a directory is acting as a mountpoint for another filesystem. This can be useful for various system administration tasks, such as checking if a new disk is successfully mounted.
Use case 1: Check if a directory is a mountpoint
Code:
mountpoint path/to/directory
Motivation: The mountpoint
command is useful when you want to check if a specific directory is serving as a mountpoint for another filesystem. This can help verify if a new disk or partition has been successfully mounted at the designated location.
Explanation: In this use case, we simply provide the path to the directory we want to check as an argument to the mountpoint
command.
Example output:
/path/to/directory is a mountpoint
Use case 2: Check if a directory is a mountpoint without showing any output
Code:
mountpoint -q path/to/directory
Motivation: Sometimes, you may want to perform a check silently without displaying any output on the console. This can be useful if you are scripting or automating tasks and want to use the result of the check in your script directly, without any extra messages cluttering the output.
Explanation: By adding the -q
option to the mountpoint
command, it runs in quiet mode. This means that it won’t display any output on the console. Instead, it will only return the appropriate exit code - 0 if the directory is a mountpoint, or 1 if it is not.
Example output: (no visible output, but the command will return the appropriate exit code for further processing)
Use case 3: Show major/minor numbers of a mountpoint’s filesystem
Code:
mountpoint --fs-devno path/to/directory
Motivation: When managing different filesystems mounted on a system, you may need to gather more information about a specific mountpoint. This can include details such as the major and minor numbers, which uniquely identify the filesystem device.
Explanation: The --fs-devno
option is used to display the major and minor numbers of the filesystem associated with the specified mountpoint directory. The major number represents the type of device (e.g., a hard drive or a USB flash drive), while the minor number represents a specific instance of that device.
Example output:
/dev/sdb1 8:17
Conclusion:
The mountpoint
command provides a simple and efficient way to check if a directory is acting as a mountpoint for another filesystem. By using different options, such as -q
or --fs-devno
, you can control the output and obtain additional information about the mounted filesystem. This command can be particularly useful for system administrators and script developers who need to validate mountpoints or gather specific details about mounted filesystems.