Filtering Locally-Mounted Filesystems in Linux: df and mount Command Options Explained


2 views

As Linux system administrators, we frequently need to check disk usage and mounted filesystems. The standard tools like df and mount show everything - local disks, NFS shares, SMB mounts, and other network filesystems. This becomes problematic when you only care about local storage.

The df command has a -l or --local flag that does exactly what we need:


df -l
# or equivalently
df --local

This will only show filesystems that are physically attached to the local machine. Here's a comparison of outputs:


# Standard df output
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   15G   33G  32% /
nfs-server:/data 2.0T  1.4T  612G  70% /mnt/nfs
//smb/share      500G  200G  300G  40% /mnt/smb

# Filtered output
$ df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   15G   33G  32% /

For the mount command, we can combine it with grep to achieve similar filtering:


mount | grep '^/dev'

Or more precisely using findmnt (which is part of util-linux):


findmnt -l -o SOURCE,TARGET,FSTYPE -t ext4,xfs,btrfs

For more control, we can create a shell function in our .bashrc:


localdf() {
    df -h | awk 'NR==1 || /^\/dev/'
}

localmount() {
    mount | grep -E '^/dev|^overlay|^tmpfs|^proc'
}

Here are common local filesystem types you might want to include:

  • ext4
  • xfs
  • btrfs
  • zfs
  • tmpfs
  • proc
  • sysfs

When dealing with thousands of mounts, these commands can significantly improve performance:


# Using findmnt for faster filtering
findmnt -nr -o TARGET -t ext4,xfs,btrfs | xargs -I{} df -h {}

For frequent use, consider creating aliases in your shell configuration:


alias ldf='df -l'
alias lmount='mount | grep -E "^/dev|^overlay|^tmpfs|^proc"'

When administering Linux systems, I constantly need to check local storage while ignoring various network-mounted filesystems (NFS, SMB, CIFS, etc.). The default outputs from df -h and mount clutter the display with all mounted filesystems, forcing manual filtering:


$ df -h | egrep -v 'nfs|smb|cifs'

For df, use the -l or --local flag to show only local filesystems:


$ df -hl
$ df --local -h

For mount, combine with grep for better filtering:


$ mount | grep '^/dev'

Create a bash function for reusable local FS checks:


localfs() {
  df -hl --output=source,target,fstype,size,used,avail,pcent | \
  awk 'NR==1 || /^\/dev/'
}

When you need more granular control over excluded types:


$ df -h -x tmpfs -x devtmpfs -x nfs -x cifs

For mount, use type filtering with -t:


$ mount -t ext4 -t xfs -t btrfs

For permanent solutions, modify /etc/fstab to separate local and network mounts into different sections with comments. Example fstab structure:


# Local filesystems
/dev/sda1  /          ext4  defaults  0 1
/dev/sdb1  /data      xfs   defaults  0 2

# Network filesystems
nas:/share /mnt/nas   nfs   ro        0 0