Skip to content

Instantly share code, notes, and snippets.

@solsticedhiver
Forked from tsbertalan/killsnaps.sh
Last active November 24, 2018 19:17
Show Gist options
  • Save solsticedhiver/b820b74648ebb7de37940d2ee55fd56a to your computer and use it in GitHub Desktop.
Save solsticedhiver/b820b74648ebb7de37940d2ee55fd56a to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
export IFS='
'
# that's a dangerous script to run because it removes all your snaps. Don't do that
function echo_cmd() {
echo "$@"
#$@
}
snaps=`mktemp -p /tmp remove-snaps.XXXXXX.txt`
echo ":: Listing mounts ..."
for f in $(df | awk "{ print \$6 }" | grep snap | sort)
do
echo "$f"|tee -a $snaps
done
echo ":: Unmounting ..."
for item in `cat $snaps`
do
echo_cmd "sudo umount $item"
done
echo ":: Removing folders ..."
for item in `cat $snaps`
do
echo_cmd "sudo rmdir $item"
done
echo ":: Removing files ..."
for item in `cat $snaps`
do
snap=`echo $item | sed 's/\/snap\///g' | sed 's/\//_/g'`
echo_cmd "sudo rm /var/lib/snapd/snaps/$snap.snap"
done
rm $snaps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment