Created
November 13, 2021 19:20
-
-
Save kristofgilicze/8dc13d33053ad5a033c1eea39bd76399 to your computer and use it in GitHub Desktop.
Remove old snap revisions to clean up some space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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