Created
January 19, 2025 10:25
-
-
Save sudoevans/3dfe3886a6e8e2b0cf3f4203eb2fda18 to your computer and use it in GitHub Desktop.
Remove unwanted kernels
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 | |
| # Remove unwanted kernels. | |
| uname -a | |
| IN_USE=$(uname -a | awk '{ print $3 }' ) | |
| echo "You are currently running $IN_USE" | |
| OLD_KERNELS=$( | |
| dpkg --list | | |
| grep -v "$IN_USE" | | |
| grep -Ei 'linux-image|linux-headers|linux-modules' | | |
| awk '{ print $2 }' | |
| ) | |
| echo "Old Kernels to be removed: " | |
| echo "$OLD_KERNELS" | |
| if ["$1"=="exec" ]; then | |
| for PACKAGE in $OLD_KERNELS; do | |
| yes | apt purge "$PACKAGE" | |
| done | |
| else | |
| echo "If all looks good, run with exec arguement" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment