25

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).

Anthon
  • 79,293
Johran
  • 253
  • 3
  • 6
  • alias mnt="mount | grep '^/dev'" i use this to show the "devices" only. – pcarvalho Jan 13 '19 at 15:50
  • 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. – Fran Jun 02 '20 at 07:12

8 Answers8

47

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.

mikeserv
  • 58,310
  • Thanks, I had no idea findmnt existed! To filter the filesystems, you could use $(awk '/nodev/ { print $2 }' /proc/filesystems | paste -sd,) – deltab Jan 02 '15 at 16:15
  • @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. – mikeserv Jan 03 '15 at 05:25
  • 5
    @insaner - that is more than enough, I assure you. I'm very flattered, thank you. But by the way, if findmnt surprised you then you might want top poke around a bit in the util-linux package - linux's libmount and friends have seen some pretty significant updates in the not too distant past. There's some pretty cool stuff in there. You might also like a look at the mount namespaces and shared mount trees. – mikeserv Feb 01 '15 at 02:30
  • 3
    @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. – mikeserv Feb 02 '15 at 17:55
  • Added some more pseudo filesystems to ignore: findmnt -it autofs,cgroup,cgroup2,configfs,debugfs,devtmpfs,devpts,fuse,fuse.gvfsd-fuse,fusectl,hugetlbfs,mqueue,proc,pstore,securityfs,squashfs,sysfs,tmpfs – Mark Jeronimus Jul 13 '20 at 08:58
13

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).

Graeme
  • 34,027
Anthon
  • 79,293
8

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 '^[^ ]*[/:]'
Graeme
  • 34,027
8

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.

Sebastian
  • 8,817
  • 4
  • 40
  • 49
  • 1
    The nice thing about lsblk -f is that unlike mount and findmnt will also show devices that are not currently mounted. – ccpizza Dec 09 '23 at 08:56
2

A list of file system using a block device as backing storage can be obtained from /proc/filesystems. For example you could use it as follows:

mount -t "$(grep -v '^nodev' /proc/filesystems | cut -f2 | paste -s -d ,)"

Since you want both file systems backed by a block device and network file systems, it does not completely eliminate the need to maintain a list manually. But then you would only have to maintain a list of the network file systems you use.

I don't know how /proc/filesystems will treat those file systems which use multiple block devices for backing storage (i.e. file systems with RAID build into the file system). You might have to treat those special.

kasperd
  • 3,580
2

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

df -h | grep -P '^(F|/|[\w@.-]+:/)'

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|/|[\w@.-]+:/)'

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.

1

Do not use the -v switch.

Use:

mount | grep -Ew 'ext4|ext3'

This will show you only ext4 and ext3. If you want to view more filesystems, add them to the regex.

For example, to view ext3, ext4, cifs and nfs mounts, use:

mount | grep -Ew 'ext4|ext3|cifs|nfs'

Sreeraj
  • 5,062
  • 1
    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. – Anthon Jan 02 '15 at 09:27
  • @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. – Sreeraj Jan 02 '15 at 10:10
  • 1
    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 Jan 02 '15 at 10:18
0

Best I use as an alias:

df -Th| grep -Ev '(udev|tmpfs)''

sample output:

# df -Th| grep -Ev '(udev|tmpfs)'
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/md3       ext4       39G  792M   36G   3% /
/dev/md2       ext4      487M   32M  426M   7% /boot
/dev/sda1      vfat      510M  152K  510M   1% /boot/efi
/dev/md5       ext4      7.2T  311M  6.8T   1% /var

but some of the answers above are very useful I might switch :

findmnt --df

lsblk -f

Nadir
  • 141