Skip to content

Instantly share code, notes, and snippets.

@chluehr
Created June 16, 2015 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chluehr/20b0e122f4e213844c6c to your computer and use it in GitHub Desktop.
Save chluehr/20b0e122f4e213844c6c to your computer and use it in GitHub Desktop.
Simple Script to delete all old kernels except the last recent 2 (after auto-updates) - use with caution
#!/bin/bash
OLD=$(ls -tr /boot/vmlinuz-* | head -n -3 | cut -d- -f2- |
awk '{print "linux-image-" $0 " linux-headers-" $0}' )
echo "OLD:"
echo "$OLD"
echo
echo -n "CURRENT: "
uname -r
echo "continue?"
read DUMMY
if [ -n "$OLD" ]; then
apt-get -qy remove --purge $OLD
fi
apt-get -qy autoremove --purge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment