Table of Contents
This tip is about the how to Utilise the findmnt Command on Linux. So read this free guide, How to Utilise the findmnt Command on Linux step by step. If you have query related to same article you may contact us.
How to Utilise the findmnt Command on Linux – Guide
I’ve been working on a bash script project to automatically build Linux from scratch. Each time I step through the code, I trace the method to make it cleaner. I take a small segment of code and improve it. A few days ago I was doing a modification to check if a filesystem is mounted before mounting it. I was looking for a superior method to do so. I would prefer not to use the default mount | grep or any similar code. I needed something cleaner.
How to Use the findmnt command on Linux
Fedora users can install the package as follows
$ sudo yum install util-linux-ng
Findmnt default option
This command will by default give a list of all mounted file systems if no mount point or device is specified.
$ findmnt
Findmnt polling mode
The findmnt command can be used to monitor changes to the /proc/self/mountinfo file. Polling mode can be invoked by typing in your terminal the following command:
$ findmnt -p
alternatively
$ findmnt -poll
Any changes made to the /proc/self/mountinfo file will be automatically updated in the terminal. At first you won’t see any output, but if you try to disconnect and connect your flash drive, the changes will be reflected in the terminal, as in the following example. The time that polling mode will block can be restricted by the timeout or the first option.
timeout option
This option can be used in conjunction with poll to limit the time that polling mode will block to the time you have explicitly set. The timeout to be set is in milliseconds. After the timeout period, findmnt will no longer monitor changes to the /proc/self/mountinfo file.
$ findmnt –poll –timeout 6000
First option
The first-only option will monitor changes to the /proc/self/mountinfo file only for the first change and the command will no longer be in polling mode. The first change is displayed in the terminal and the prompt is returned to you. To use this option type in your terminal:
$ findmnt –poll –first-only
Similar as df output
The findmnt command can also be used to mimic the output you would get if you used the df command. You can achieve this by running the findmnt command with the –df option as shown in the following example.
$ findmnt -df
or
$ findmnt -D
This will give you almost identical output if you ran the df command with the -h option.
$ df -h
Findmnt list option
If you don’t like the default tree output, you can use the list or -l option. This will print your output in a list format.
$ findmnt -list
Running this command will give you output like this:
Findmnt Evaluate Option
The evaluation option will convert all tags eg LABEL, UUID, PARTUUID or PARTLABEL to the actual device name. This option can be combined with the fstab option to print all file systems in /etc/fstab. The fstab option is output in list format, so there is no need to call the list option when fstab is used.
$ findmnt –fstab –evaluate
When the two options are combined as follows, the output will look similar to the example below.
Findmnt type option
This option allows you to limit the set of file systems printed. Multiple file systems can be specified and separated by a comma. In this example, the command will look for the ext4, ext3, and vfat file systems.
$ findmnt -t ext4,ext3,vfat
Final note
I hope you like the guide How to Utilise the findmnt Command on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.