Skip to content

Instantly share code, notes, and snippets.

@sudoevans
Created January 19, 2025 10:25
Show Gist options
  • Select an option

  • Save sudoevans/3dfe3886a6e8e2b0cf3f4203eb2fda18 to your computer and use it in GitHub Desktop.

Select an option

Save sudoevans/3dfe3886a6e8e2b0cf3f4203eb2fda18 to your computer and use it in GitHub Desktop.
Remove unwanted kernels
#!/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