If you use Snap packages on Ubuntu or another Linux distribution, you may eventually notice that Snap keeps older revisions of packages around. That's intentional. Snap keeps previous revisions so that packages can be rolled back if necessary. The downside is that those old revisions can accumulate over time. If you run
snap list --all
you may see something like:
Name        Version      Rev    Tracking       Publisher   Notes
core22      2025...      1234   latest/stable  canonical✓  base
core22      2025...      1200   latest/stable  canonical✓  disabled
snapd       2...          3000   latest/stable  canonical✓  snapd
snapd       2...          2950   latest/stable  canonical✓  disabled
Those disabled entries are older revisions that are no longer active. You can remove them manually, but a small Bash function can make the cleanup much easier.

The Bash function

Add this to your ~/.bashrc:
# Custom function to delete disabled snap installs
removedisabledsnap() {
    snap list --all | awk '$NF == "disabled" {print $1, $3}' |
    while read snap rev; do
        sudo snap remove "$snap" --revision="$rev"
    done
}
Then reload your Bash configuration:
source ~/.bashrc
You can now run
removedisabledsnap
The function will find the disabled Snap revisions and remove those specific revisions.

What is a Snap revision?

Snap packages are versioned using revisions. When Snap updates a package, the new revision becomes active while an older revision may remain installed so it can be used for rollback. That's why you can sometimes see multiple revisions of the same package:
snap list --all
The important part is the disabled marker, like an entry such as
firefox    ...    6000    ...    disabled
is not the currently active Firefox revision. It's an older revision retained by Snap.

How does the function find disabled revisions?

The first part is:
snap list --all
This gives us all installed Snap revisions, including disabled ones. The output is then passed to awk:
awk '$NF == "disabled" {print $1, $3}'
$NF means the last field in the current line. So
$NF == "disabled"
means that awk only selects lines where the final column says disabled. Then
{print $1, $3}
prints the first and third columns: the Snap name and its revision number. The result might therefore look like:
firefox 6000
core22 1200
snapd 2950

The while loop

That output is then fed into:
while read snap rev; do
    sudo snap remove "$snap" --revision="$rev"
done
For every line, Bash puts the first value into snap and the second value into rev. So
firefox 6000
becomes:
snap = firefox
rev  = 6000
The function then runs:
sudo snap remove "firefox" --revision="6000"
It repeats this for every disabled revision it found.

Why use --revision?

This is an important detail. We don't want to remove the Snap package itself. We only want to remove a specific old revision. That's why the function uses:
snap remove "$snap" --revision="$rev"
The revision number tells Snap exactly which revision should be removed. The active revision remains installed.

Is it safe?

For its intended purpose, this is a reasonable cleanup operation because the function specifically targets revisions that Snap reports as disabled. It does not simply remove every Snap package - It asks Snap to remove a specific old revision. However, Snap does keep older revisions for a reason, simply that they provide a local rollback option. If you remove those old revisions, you lose that particular rollback copy. For machines where disk space matters, periodically cleaning up disabled revisions can nevertheless be useful - Just like on mine.

See what will be removed first

You don't have to run the cleanup function blindly. You can first see which disabled revisions exist:
snap list --all | awk '$NF == "disabled" {print $1, $3}'
For example:
core22 1200
firefox 6000
snapd 2950
If those are the old revisions you want to remove, run
removedisabledsnap

Why put it in ~/.bashrc?

I put the function, in my ~/.bashrc so I can run it from any terminal session without having to remember the full command sequence every time I want to clean up disabled Snap revisions.

One small command worth keeping around

The nice thing about Bash functions is that they don't have to be complicated. This one combines a few standard Linux tools:
  • snap to inspect installed Snap revisions.
  • awk to find only disabled revisions.
  • while read to process them one at a time.
  • snap remove --revision to remove the specific old revision.
Once wrapped in removedisabledsnap, the whole process becomes one memorable command. And that's really the point of these little ~/.bashrc functions - take something you occasionally need, make it repeatable, and give yourself a command that's easy to remember.