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).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:
-ior--invert- invert the sense of matching
-Ror--submounts- print all submounts for the matching filesystems
-tor--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/fstabfilesystems where the mountpoint directory is/mnt/foo. It also prints--bindmounts where/mnt/foois 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 -Dorfindmnt --df- Imitate the output of
df(1). This option is equivalent to-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGETbut excludes all pseudo filesystems. Use--allto print all filesystems.
- Imitate the output of
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.
Method 2
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).
Method 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 '^[^ ]*[/:]'
Method 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.
Method 5
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'
Method 6
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.
Method 7
Combining several answers here (and expanding just a bit), here’s what works best for me:
df -h | grep -P '^(F|/|[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b780eeed">[email protected]</a>]+:/)'
How I got here:
findmnt -Dis close, but it still includes a lot oftmpfssystems 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 theFSTYPEcolumn, 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 -Eforgrep -P, which allows me to replace the more verbose[:alnum:]with the more compactw. - 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
Fto the alternation, I retain the header line; a nicety only, but still handy.
- I swapped
- I did not personally need the
--color=never(because I don’t use analiasedgrep), 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|/|[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8bf88e6e5">[email protected]</a>]+:/)'
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.
Method 8
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0