RemoveOldKernels
Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules
The former is useful, but it only removes the kernels. I want to remove all headers, etc. associated with them. So, before I run the command from the latter blog post, I just want to confirm what I'm going to remove, as should you, with the following code (note, not as root just to be even more cautious):
Perfect, now I can just run the one-liner from that latter blog post:dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
Boom, I just got rid of over 3 GB's of old linux kernels on my system.