Created
January 29, 2025 13:14
-
-
Save enoch85/ebf0292fccfb4cec962962f4f1d88e69 to your computer and use it in GitHub Desktop.
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 | |
# Run this script without any param for a dry run | |
# Run the script with root and with exec param for removing old kernels after checking | |
# the list printed in the dry run | |
uname -a | |
IN_USE=$(uname -a | awk '{ print $3 }') | |
echo "Your in use kernel is $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 it again like this: sudo remove_old_kernels.sh exec" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment