Cleaning Up Linux Headers

  • Post by Mike Dixson
  • Oct 09, 2014
post-thumb

Make sure you’ve rebooted BEFORE running any of these commands so that you are actively using the latest kernel.

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

If you’ve had a previous apt-get install fail due to disk space issues and you’re trying to clean up the linux headers to free disk space run the below command which will force the purge
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y -f purge