Remove old version of SNAP installed in Ubuntu

Many a time we ran into a low storage problem on ubuntu and we start searching for disk usages using some utility like “Disk Usage Analyser”.

And you some significant disk usage by “/var/lib/snapd/snaps” directory

snaps in /var/lib/snapd/snaps folder

You can see there are multiple snaps for slack in the above screenshot.

slack_37.snap & slack_38.snap

And we don’t need slack_37.snap anymore as we already have a newer version of slack installed.

So to identify and remove such unnecessary old version of snaps we can use the following bash commands

  1. List all snaps we use
snap list — all

2. Get disabled snaps name and revision

snap list --all | awk '/disabled/{print $1, $3}'

3. Remove each disabled snaps

snap list --all | awk '/disabled/{print $1, $3}' | 
while read snapname revision;
do snap remove "$snapname" --revision="$revision"
done

You can write a shell script for this as well, Which will be handy for you in future

#!/bin/bash

Cofounded Accunity Services (Software Consultancy Firm) and Passionate Coder at Heart. reach me at kiran@accunityservices.com