What is the mountpoint command? In this post, you will learn about the mountpoint command, and in the video, a shell script is written using the mountpoint command to check whether a directory is a mount point or not.
The mountpoint
command in Linux is used to determine if a directory or file is a mount point. A mount point is a directory where a filesystem is mounted, allowing access to the files within the filesystem through that directory.
The basic usage of the mountpoint
command is as follows:
mountpoint [-d|-q] directory|file
In the command above, -d
or -q
are optional flags. -d
makes the command return a description, while -q
makes the command operate quietly, returning no output and only setting the exit status.
The mountpoint
command checks if the given directory or file is mentioned in the /proc/self/mountinfo
file. If the directory or file is a mount point, the command returns a success status (0). If the directory or file is not a mount point, or if there is an incorrect invocation, permission issue, or system error, the command returns a failure status (1 or 32).
Here’s an example of how you might use the mountpoint
command:
mountpoint /mnt/mydisk
This command will check if /mnt/mydisk
is a mount point. If it is, the command will return a success status and print a message indicating that /mnt/mydisk
is a mount point. If it isn't, the command will return a failure status.
More shell script videos and linux tutorials on my YouTube Channel.