Created
December 5, 2022 11:16
-
-
Save blizzz/40eb3ed73372692ac26603b35075e46b to your computer and use it in GitHub Desktop.
remove old installed linux kernel (tested on ubuntu releases)
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 bash | |
# ⚠️ ATTENTION! It purges kernels without asking for confirmation!!! | |
CURRENT_KERNEL=$(uname -r | grep -oE '[0-9\.]+-[0-9]+') | |
LATEST_KERNEL=$(apt show linux-image-generic | grep -oE 'linux-image-[0-9\.]+-[0-9]+' | cut -d '-' -f3-) | |
BASE_KERNEL=$(echo ${CURRENT_KERNEL} | cut -d '.' -f 1-2) | |
apt list --installed | grep linux | cut -d '/' -f 1 | egrep -v "(${CURRENT_KERNEL}|${LATEST_KERNEL})" | grep "${BASE_KERNEL}." | tr '\n' ' ' | xargs apt purge -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment