Skip to content

Instantly share code, notes, and snippets.

@MichaelF25
Last active March 31, 2017 06:30
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 MichaelF25/43c782e26d3d7e4fc56eeed1d69caa4e to your computer and use it in GitHub Desktop.
Save MichaelF25/43c782e26d3d7e4fc56eeed1d69caa4e to your computer and use it in GitHub Desktop.
Remove old kernel images in Ubuntu if apt-get autoremove is broken
#!/bin/sh
# first check current kernel version
uname -a
# generate list of dpkg commands to remove older kernel versions
for i in `dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) | grep ^ii | awk '{print $2}'`; do echo sudo dpkg --purge $i; done
# remove old kernel versions
#for i in `dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) | grep ^ii | awk '{print $2}'`; do sudo dpkg --purge $i; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment