Sunday, August 31, 2014

Ubuntu: Auto remove old kernels when you are running out of space

If your root partition is running out of space, you can auto remove the old kernels with this command in the terminal:

 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  

Source: https://help.ubuntu.com/community/Lubuntu/Documentation/RemoveOldKernels