Last active
June 22, 2022 08:25
-
-
Save calpaterson/2223812748415a8dcb1727bb7f1e1f15 to your computer and use it in GitHub Desktop.
remove-unneeded-kernels.fish
This file contains 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
#!/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