63

Ubuntu is using snaps, shown below

Core applications packaged as snaps

Shown here

enter image description here


So, my question is, that since snaps are shown using the df command, and they apparently flood df.

It's just flooding df, and makes it harder to use. Is there a way to stop it? I'm assuming since snap is planning on being used more frequently it will either no show in df, or df will become a much longer command with more pipes.

Jorge Castro
  • 71,754
  • 7
    You can perhaps do df | grep -v "/snap" or similar, but aside from that, no,. Snaps are mounted and so will show up in things which show what is mounted. – dobey Apr 29 '18 at 02:28
  • 2
    Perhaps you could open a bug report at https://launchpad.net/+ubuntu/source/coreutils about installed snaps being unhelpful in the output. – dobey Apr 29 '18 at 02:41
  • 2
    You can prevent df from listing snaps with the following: df $(cut -d' ' -f3 /proc/mounts | sort -u | grep -v 'squashfs' | sed 's/^/-t /') – Martin Wimpress May 01 '18 at 14:20
  • 2
    I setup an alias: alias df='df | grep -v "/snap"' – Mike Redrobe Sep 19 '18 at 14:19
  • 4
    Instead of piping df results to grep & removing snaps, the cleaner solution is IMHO to use grep's grep -v option to exclude file systems. Snaps use squashfs. Thus you can define an alias like alias df='df -l -BM -Tx"squashfs"' to get the non-snap-list as a default. See [https://docs.snapcraft.io/the-snap-format/698] for a definition. – Marcus Oct 28 '18 at 10:31
  • 1
    @marcus It's a possible solution. Make that an answer instead of a comment. – Sergiy Kolodyazhnyy Nov 01 '18 at 16:26
  • 'df -h | egrep -vi snap' is what i use – Ronald Johnson Sep 13 '22 at 16:21

4 Answers4

77

You can use df's df -x option to exclude certain file systems from the results. Since snaps use the squashfs filesystem, you can define an alias like

alias df='df -x"squashfs"'

to get the non-snap-list as a default.

BTW, see this link for a definition of the snap format.

Marcus
  • 1,029
  • 3
    I'm generally against using alias', but I may make an exception here. Thanks! – trueCamelType Nov 01 '18 at 22:08
  • 1
    I still prefer the grep solution as this would remove all squashfs filesystems, which is not limited to snaps. – Jelle De Loecker Nov 25 '18 at 13:04
  • 3
    the difference is that the grep solution prevents other arguments to df from working. – 300D7309EF17 Feb 19 '19 at 23:30
  • @tedder42 function df() { command df "$@" | grep -v "/snap"; } – mxmlnkn Mar 24 '20 at 17:54
  • 1
    how is this better than the proper use of df as listed in the answer, @mxmlnkn? – 300D7309EF17 Mar 24 '20 at 17:57
  • @tedder42 I prefer it because there might be other valid usecases for squashfs mounts, which I'd want to see. I only want to filter snap. But I only commented this as a response as to how command line arguments would still work by using a function and forwarding the arguments with $@ instead of an alias. – mxmlnkn Mar 24 '20 at 19:01
  • 5
    The previous function also removes lines which just happen to contain /snap. My function improves this as well as hide some other 'filesystems' I'm not interested in: function df() { command df $@ | grep -vE "(% /snap/)|(^tmpfs )|(^udev )"; } – Mark Jeronimus Apr 17 '20 at 10:33
  • 1
    @MarkJeronimus I'm no regex expert, but those parenthesis to mark atoms around each of the terms seem superfluous. Can you explain why they are necessary if they are? Thanks. Both "(% /snap/|^tmpfs |^udev )" and just "% /snap/|^tmpfs |^udev " should work fine I think. – b-jazz Sep 25 '20 at 17:32
  • 1
    I'm no regex expert either and in the past I've struggled a lot with the 'alternatives' syntax not working. I think I copy/pasted this from somewhere and was happy it worked at all. On to regex101.com which I just tried, you should use Python syntax to prevent / from being interpreted as regex delimiters. – Mark Jeronimus Sep 28 '20 at 12:22
  • I also use alias m='mount | g -v -e cgroup -e fs' to remove all the crap added to mount. – alchemy Mar 28 '22 at 20:32
  • bash: g: command not found – Theodore R. Smith Nov 28 '23 at 05:10
7

All the snap filesystems start as /snap/ so one can use the following command:

df | grep -v /snap

The -v inverses the grep search (list things that don't match).

The advantage of this is that it will still show squashfs filesystems if you want them.

You can still use an alias if you wish:

alias df='df | grep -v /snap'

Works With Other Tools (Pydf)

Also, because this is using a pipe to grep, rather than an option of df, you can use it for other tools such as pydf.

E.g.

pydf | grep -v /snap
Programster
  • 5,871
  • Using an alias means that you lose access to flags (df -h), so I tweaked this solution to use a function instead: df() { command df "$*" | command grep -v /snap; } and added it to my ~/.bashrc. This way I can still use df -h (or other flags) while still removing the annoyingly large list of snap mountpoints. – Compholio Feb 03 '22 at 19:29
5

I find this one quite handy;

df -Thx squashfs
eekfonky
  • 329
0

The number of way to do this is astronomical ;)

df | sed /snap/d

miigotu
  • 484