Cleaning Up Linux Headers

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

2 thoughts on “Cleaning Up Linux Headers

  1. Hi Colin,

    Curious, I’ve used this technique a fair few times now with no issue. Did you restart before you run the header removals?


Leave a Reply