Skip to content

Instantly share code, notes, and snippets.

@jklmnn
Last active February 2, 2017 13:30
Show Gist options
  • Save jklmnn/d4e84a10442e5ff8b9e589499d2aeeed to your computer and use it in GitHub Desktop.
Save jklmnn/d4e84a10442e5ff8b9e589499d2aeeed to your computer and use it in GitHub Desktop.
Removes all kernels installed under Debian/Ubuntu that aren't loaded.
#!/bin/bash
kernels=$(dpkg -l | grep -E "ii linux-(image|headers)-[0-9]\.[0-9]\.[0-9]-.*" | grep -v $(uname -r | cut -d"-" -f1,2) | cut -d" " -f3)
echo "Current kernel: $(uname -r)"
echo "Remove kernels:"
echo "$kernels"
read -p "Execute? (y/n)" choice
if [ "$choice" == "y" ]
then
echo $kernels | xargs sudo apt-get remove -y
else
echo "Abort."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment