Showing only "interesting" mount points / filtering non interesting types

8,327

Solution 1

The -t option for mount also works when displaying mount points and takes a comma separated list of filesystem types:

mount -t ext3,ext4,cifs,nfs,nfs4,zfs

I am not sure if that is a better solution. If you start using (e.g. btrfs) and forget to add that to the list you will not see it and maybe not miss it. I'd rather actively filter out any new "uninteresting" filesystem when they pop up, even though that list is getting long.

You can actively try to only grep the interesting mount points similar to what @Graeme proposed, but since you are interested in NFS/CIFS mounts as well (which don't start with /), you should do:

mount | grep -E --color=never  '^(/|[[:alnum:]\.-]*:/)'

( the --color is necessary to suppress coloring of the initial / on the lines found). As Graeme pointed out name based mounting of NFS shares should be allowed as well. The pattern either selects lines starting with a / or any combination of "a-zA-Z0-9." followed by :/ (for NFS mounts).

Solution 2

Do not use mount.

From man mount:

  • The listing.
    • The listing mode is maintained for backward compatibility only.
    • For more robust and customizable output use findmnt(8), especially in your scripts.
    • Note that control characters in the mountpoint name are replaced with ?.

Use findmnt, as the documentation suggests. Here are a few interesting options as described by findmnt --help:

  • -i or --invert
    • invert the sense of matching
  • -R or --submounts
    • print all submounts for the matching filesystems
  • -t or --typeslist
    • limit the set of filesystems by FS types

Those are only a couple of the many filters you can apply on the commandline.

man findmnt
  • EXAMPLES
    • findmnt --fstab -t nfs
    • Prints all NFS filesystems defined in /etc/fstab.
    • findmnt --fstab /mnt/foo
    • Prints all /etc/fstab filesystems where the mountpoint directory is /mnt/foo. It also prints --bind mounts where /mnt/foo is a source.

You might use:

findmnt -it sysfs,cgroup,proc,devtmpfs,devpts,pstore,debugfs,hugetlbfs,mqueue,configfs

That should filter out all pseudo-filesystems, I believe.

Still, you can do the same with mount:

mount -t nosysfs,nodevtmpfs...

Possibly a better way might be to use one of either the following commands, which findmnt --help describes as noted:

  • findmnt -D or findmnt --df
    • Imitate the output of df(1). This option is equivalent to -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET but excludes all pseudo filesystems. Use --all to print all filesystems.

You can add list fields to the defaults with findmnt -Do+field,+field.... You can specify your own list of fields using only the file-systems -D would show by omitting the + like findmnt -Dofield,field.

Solution 3

How about:

mount | grep '^/[^/]'

Mount points relating to physical disks will always start with a / since the first field is the path to a device. cifs mounts will start with // so exclude lines with a second / to ignore them.

Update

I misread the question, I thought you wanted to exclude cifs and nfs. Try this instead:

 mount | grep -E '^[^ ]*[/:]'

Solution 4

Late in the party, but

I don't want to see the not so interesting ones (i.e. non-physical)

If by physical, you mean block devices attached to your PC, go with

$ lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sdb             8:16   0 238.5G  0 disk  
├─sdb1          8:17   0   100M  0 part  /boot
├─sdb2          8:18   0     1G  0 part  
├─sdb3          8:19   0    45G  0 part  /
└─sdb4          8:20   0 192.4G  0 part  
  └─ssdhomecr 254:0    0 192.4G  0 crypt /home
sdi             8:128  0 931.5G  0 disk  
├─sdi1          8:129  0   801G  0 part  
│ └─test      254:2    0   801G  0 crypt /mnt/esata
└─sdi2          8:130  0 130.6G  0 part  

I often use it with the --fs/-f switch (file system information)

$ lsblk -f 
NAME          FSTYPE      LABEL  UUID                                 MOUNTPOINT
sdb
├─sdb1        ext2        bootp  7cf4f62a-1111-4e2f-7536-4fc5ad38bd2c /boot
├─sdb2        swap        swapp  4aa6d4ae-11e7-4a35-8bf3-ab42313aca62
├─sdb3        ext4        sysp   b23338ad-5a4b54i54-a842-8164-a9a9a2a /
└─sdb4        crypto_LUKS        112c40c9-7fdd-4158-895c-5344d24c4a6d
  └─ssdhomecr ext4        homecr fc8a92cb-124f-4a0d-b88e-2055c06ffc3g /home
sdi
├─sdi1        crypto_LUKS        a7c9fg87-6962-43e3-b8c6-7605b181630e
│ └─test      ext2        esata1 124657dc-671a-4b7f-b8a7-b64d5341cabe /mnt/esata
└─sdi2        crypto_LUKS        1c5846bb-ce7e-4cbe-bb0a-b687758ea1dc

lsblk is part of util-linux. Obviously, it will not show fuse or network mounts.

Solution 5

Combining several answers here (and expanding just a bit), here's what works best for me:

df -h | grep -P '^(F|/|[\[email protected]]+:/)'

How I got here:

  • findmnt -D is close, but it still includes a lot of tmpfs systems that I don't want to see.
  • Of course, at the point at which you're simulating df -h, why not just run that? The layout is a bit nicer, and the only thing you lose is the FSTYPE column, which I personally don't miss. (For those that do, see below.)
  • The regex in the accepted answer is just about perfect, but I tweaked it as follows:
    • I swapped grep -E for grep -P, which allows me to replace the more verbose [:alnum:] with the more compact \w.
    • It is not necessary to escape the . character when it's inside a character class.
    • A remote-mounted filesystem can contain an @ if the user is included in the hostname (which I actually have an example of on my machine).
    • By adding F to the alternation, I retain the header line; a nicety only, but still handy.
  • I did not personally need the --color=never (because I don't use an aliased grep), but you could add that back in if you need it for your system.

If you really need to see the FSTYPE column, you can easily adapt this method to findmnt like so:

findmnt -D | grep -P '^(S|/|[\[email protected]]+:/)'

Note that the only real difference on the grep side is that you have to swap F for S, because df's header line starts with Filesystem while findmnt's starts with SOURCE.

Share:
8,327

Related videos on Youtube

Johran
Author by

Johran

Updated on September 18, 2022

Comments

  • Johran
    Johran over 1 year

    I used mount to show mounted drives, I don't want to see the not so interesting ones (i.e. non-physical). So I used to have a script mnt that did:

    mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts) '
    

    under Ubuntu 8.04 and showed me ext3 and reiserfs mount points only. That line is actually commented out and now I use (for Ubuntu 12.04):

    mount | grep -Ev 'type (proc|sysfs|tmpfs|devpts|debugfs|rpc_pipefs|nfsd|securityfs|fusectl|devtmpfs) '
    

    to only show my ext4 and zfs partitions (I dropped using reiserfs).

    Now I am preparing for Ubuntu 14.04 and the script has to be extended again (cgroup,pstore). Is there a better way to do this without having to extend the script? I am only interested in physical discs that are mounted and mounted network drives (nfs,cifs).

    • Admin
      Admin over 5 years
      df -Th| grep -Ev '(udev|tmpfs)'
    • Admin
      Admin almost 4 years
      Ah, the good old times when this was just type mount. I will never understand why this command deserved the dirty bomb of the endless tmps, cgroups, pstores, debugfs, configfs and so on, instead of use another commands for such mounts or at least show only with some non-default option.
  • Anthon
    Anthon over 9 years
    The second one will also show nfsd on /proc/fs/nfsd type nfsd (rw) on my system, the OP doesn't want that, that's why type nfsd is filtered out.
  • Johran
    Johran over 9 years
    This is not working. NFS is not shown at all, even if delete the [^] to include CIFS mounts i am interested in
  • Graeme
    Graeme over 9 years
    @Johran, updated
  • Sreeraj
    Sreeraj over 9 years
    @Anthon Thanks for pointing that out. I was trying to show the point of not using the -v. I have updated my answer. By the way, for what the OP is trying to achieve, your method (using mount -t) is the best.
  • Graeme
    Graeme over 9 years
    Do nfs mounts always show up with IP address or could there be hostnames as well? If so this won't work.
  • Anthon
    Anthon over 9 years
    I am not sure if -t is best myself. That I would forget to expand (if I start using btrfs or xfs) is unlikely, but forgetting vfat ( iso9660) for automounted (USB) physical drives is for real. I rather have a noticeable thing to filter than missing an (unseen) one I want.
  • Anthon
    Anthon over 9 years
    @Graeme You are right (took me a while to check that out as the NFS mounting is not working). Updated.
  • Graeme
    Graeme over 9 years
    Hostnames can have a hyphen too :)
  • Anthon
    Anthon over 9 years
    @Graeme Thanks, that is of course the "H" in the LDH rule %-)
  • deltab
    deltab over 9 years
    Thanks, I had no idea findmnt existed! To filter the filesystems, you could use $(awk '/nodev/ { print $2 }' /proc/filesystems | paste -sd,)
  • mikeserv
    mikeserv over 9 years
    @deltab - if you're filtering by mount option you might as well do that with findmnt, too. But nodev is not necessarily an option restricted to non-pseudo filesystems. On the other hand, findmnt -D will get only those.
  • Samir Daraf
    Samir Daraf over 9 years
    how can I give you more than a +1 for this? Great, great find!
  • mikeserv
    mikeserv about 9 years
    @insaner - just as an example, for basically every case you might want to use a symlink, a --bind mount will do you better. Not only can you simply track and reverse it, you can also manage the entire indirection tree in fstab. And - w/ namespaces (see unshare and nsenter) you can present different views of the filesystem per process. It is completely acceptable to, for example, --bind mount /dev/null over an arbitrary file only for an abitrary process, to do so w/out root access if fstab defines the action, and to findmnt --poll -N<pid> the current mount state at your whim.
  • Samir Daraf
    Samir Daraf about 9 years
    whoa, interesting. I've used mount --bind long ago, but to mount /dev/null over a file per process.. interesting. Thanks again!
  • ctrl-alt-delor
    ctrl-alt-delor over 5 years
    consider also findmnt
  • Mark Jeronimus
    Mark Jeronimus almost 4 years
    Added some more pseudo filesystems to ignore: findmnt -it autofs,cgroup,cgroup2,configfs,debugfs,devtmpfs,devpts,fuse,‌​fuse.gvfsd-fuse,fuse‌​ctl,hugetlbfs,mqueue‌​,proc,pstore,securit‌​yfs,squashfs,sysfs,t‌​mpfs