21

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

  • df -Th| grep -Ev '(udev|tmpfs)' – Nadir Nov 25 '18 at 12:52
  • alias mnt="mount | grep '^/dev'" i use this to show the "devices" only. – pcarvalho Jan 13 at 15:50
6

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

  • The second option looks what i want. – Johran Jan 2 '15 at 9:58
  • Do nfs mounts always show up with IP address or could there be hostnames as well? If so this won't work. – Graeme Jan 2 '15 at 10:18
  • @Graeme You are right (took me a while to check that out as the NFS mounting is not working). Updated. – Anthon Jan 2 '15 at 10:38
  • Hostnames can have a hyphen too :) – Graeme Jan 2 '15 at 10:53
  • 1
    consider also findmnt – ctrl-alt-delor Nov 25 '18 at 13:35
37

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.

  • Thanks, I had no idea findmnt existed! To filter the filesystems, you could use $(awk '/nodev/ { print $2 }' /proc/filesystems | paste -sd,) – deltab Jan 2 '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 3 '15 at 5:25
  • 1
    how can I give you more than a +1 for this? Great, great find! – insaner Feb 1 '15 at 0:24
  • 4
    @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 1 '15 at 2:30
  • 2
    @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 2 '15 at 17:55
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 '^[^ ]*[/:]'
  • 1
    This is not working. NFS is not shown at all, even if delete the [^] to include CIFS mounts i am interested in – Johran Jan 2 '15 at 9:56
  • @Johran, updated – Graeme Jan 2 '15 at 10:06
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.

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'

  • 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 2 '15 at 9: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. – Sree Jan 2 '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 2 '15 at 10:18
1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.