Remove old/disabled snaps from the system – ubuntu why…

The new snap system starts eating my system partition. Next to being slow it also holds old backups of upgraded snaps. Ubuntu itself has no option to disable that. You can only lower the number of old versions by using

sudo snap set system refresh.retain=2

which will limit the number to one live and one backup copy. But what if you also don’t need or want that backup copy? refresh.retain doesn’t allow 1:

sudo snap set system refresh.retain=1

error: cannot perform the following tasks:
- Run configure hook of "core" snap (run hook "configure": retain must be a number between 2 and 20, not "1")

I didn’t further check how to remove that but used the following one-liner to get rid of old versions:

sudo su
snap list --all | awk '$6~"disabled"{print $1" --revision "$3}' | xargs -rn3 snap remove

Next to those backups also the /var/lib/snapd/cache folder holds a massive amount of space on my machine. I considered it to be safe to delete:

sudo rm -f /var/lib/snapd/cache/*

This cleanup of snapd folder freed around 12GB of data on my root partition.