Skip to content

Instantly share code, notes, and snippets.

@kristofgilicze
Created November 13, 2021 19:20
Show Gist options
  • Save kristofgilicze/8dc13d33053ad5a033c1eea39bd76399 to your computer and use it in GitHub Desktop.
Save kristofgilicze/8dc13d33053ad5a033c1eea39bd76399 to your computer and use it in GitHub Desktop.
Remove old snap revisions to clean up some space
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
i=0
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
echo "$snapname $revision"
((i=i+1))
done
if [ "$i" -eq "0" ] ; then
exit;
fi
read -p "Remove old revisions ( make sure to close all running snaps )? [yN]: " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Elavate to root
[ "$UID" -eq 0 ] || exec sudo "$0" "$@"
echo "Removing old snap revisons to free up some space ..."
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment