How to use the command findmnt (with examples)

How to use the command findmnt (with examples)

The findmnt command is used to find and display information about mounted filesystems on a Linux system. It provides a flexible way to search for specific filesystems based on various criteria such as device, mountpoint, filesystem type, and label.

Use case 1: List all mounted filesystems

Code:

findmnt

Motivation: This use case is useful when you want to get a comprehensive list of all currently mounted filesystems on your Linux system. It can be particularly helpful when troubleshooting or examining the state of your system.

Explanation: The command findmnt without any arguments will display information about all mounted filesystems. It will provide details such as the device, mountpoint, filesystem type, and other relevant information for each mounted filesystem.

Example output:

TARGET    SOURCE     FSTYPE OPTIONS
/         /dev/sda1  ext4   rw,relatime,errors=remount-ro
/dev      udev       devtmpfs rw,nosuid,relatime,size=1816196k,nr_inodes=454049,mode=755
/sys      sysfs      sysfs  rw,nosuid,nodev,noexec,relatime
...

Use case 2: Search for a device

Code:

findmnt /dev/sdb1

Motivation: This use case is helpful when you want to find information about a specific device that is mounted as a filesystem. It allows you to quickly determine the mountpoint and other details associated with the device.

Explanation: The command findmnt followed by the device path (e.g., /dev/sdb1) will display information about the mounted filesystem associated with that device. It will provide details such as the mountpoint, filesystem type, device, and other relevant information.

Example output:

TARGET    SOURCE    FSTYPE OPTIONS
/mnt/data /dev/sdb1 ext4   rw,relatime

Use case 3: Search for a mountpoint

Code:

findmnt /

Motivation: This use case is useful when you want to find information about the mounted filesystem associated with a specific mountpoint. It allows you to quickly determine the device, filesystem type, and other details of the mounted filesystem.

Explanation: The command findmnt followed by the mountpoint (e.g., /) will display information about the mounted filesystem associated with that mountpoint. It will provide details such as the device, filesystem type, mount options, and other relevant information.

Example output:

TARGET SOURCE  FSTYPE OPTIONS
/      /dev/sda1  ext4   rw,relatime,errors=remount-ro

Use case 4: Find filesystems of a specific type

Code:

findmnt -t ext4

Motivation: This use case is useful when you want to find all mounted filesystems of a specific type. It allows you to filter the results and focus only on the filesystems that match the specified type.

Explanation: The command findmnt -t ext4 will display information about all mounted filesystems that are of the specified type (in this case, ext4). It will provide details such as the device, mountpoint, filesystem type, and other relevant information for each matching filesystem.

Example output:

TARGET    SOURCE     FSTYPE OPTIONS
/         /dev/sda1  ext4   rw,relatime,errors=remount-ro
/mnt/data /dev/sdb1  ext4   rw,relatime

Use case 5: Find filesystems with a specific label

Code:

findmnt LABEL=BigStorage

Motivation: This use case is helpful when you want to find information about mounted filesystems that have a specific label. It allows you to quickly identify the mountpoint, device, and other details associated with filesystems that match the specified label.

Explanation: The command findmnt LABEL=BigStorage will display information about mounted filesystems that have a specific label (in this case, BigStorage). It will provide details such as the mountpoint, device, filesystem type, and other relevant information for each matching filesystem.

Example output:

TARGET    SOURCE     FSTYPE OPTIONS
/mnt/data /dev/sdb1  ext4   rw,relatime

Conclusion:

The findmnt command is a powerful tool for finding and displaying information about mounted filesystems on a Linux system. It provides flexible search options based on device, mountpoint, filesystem type, and label, allowing you to quickly retrieve details about specific filesystems. Whether you need a comprehensive list of mounted filesystems or specific information about individual filesystems, the findmnt command can be a valuable resource for system administration and troubleshooting.

Related Posts

How to use the command `pw-cat` (with examples)

How to use the command `pw-cat` (with examples)

This article will illustrate different use cases of the command pw-cat.

Read More
How to use the command findfs (with examples)

How to use the command findfs (with examples)

The findfs command is used to find a filesystem by its label or UUID.

Read More
Using the xbps-query command (with examples)

Using the xbps-query command (with examples)

Introduction The xbps-query command is a utility that allows you to query package and repository information in XBPS, the package manager used by Void Linux.

Read More