Skip to content

Instantly share code, notes, and snippets.

@calpaterson
Last active June 22, 2022 08:25
Show Gist options
  • Save calpaterson/2223812748415a8dcb1727bb7f1e1f15 to your computer and use it in GitHub Desktop.
Save calpaterson/2223812748415a8dcb1727bb7f1e1f15 to your computer and use it in GitHub Desktop.
remove-unneeded-kernels.fish
#!/usr/bin/env fish
# Remove kernels older than the latest, but excluding the one currently booted
# from.
## This is ideal for when you've managed to fill your boot partition and can't
## finish an `apt upgrade`
set current_version (uname -r)
set top_version (dpkg --get-selections | grep install | awk '{print $1}' | egrep '^linux-image-[0-9].*$' | sort -r | head -n 1)
set to_remove (dpkg --get-selections | grep install | awk '{print $1}' | egrep '^linux-image-[0-9].*$' | grep -v $current_version | grep -v $top_version)
apt purge $to_remove
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment