Skip to content

Instantly share code, notes, and snippets.

@RushOnline
Created October 18, 2017 13:42
Show Gist options
  • Save RushOnline/2dcc1a8bdf2d005a030d6b093af77db8 to your computer and use it in GitHub Desktop.
Save RushOnline/2dcc1a8bdf2d005a030d6b093af77db8 to your computer and use it in GitHub Desktop.
Remove old Ubuntu kernels
#!/bin/sh
FRESH_KERNEL=$(ls -1 /boot/vmlinuz-*-generic | tail -n1 | egrep -o '[0-9]+.*')
dpkg -l linux-{image,headers}-* | awk '/^ii/{print $2}' | egrep '[0-9]+\.[0-9]+\.[0-9]+' | grep -v $(uname -r | cut -d- -f-2) | grep -v $FRESH_KERNEL | xargs apt -y purge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment