Sunday, January 31, 2016

[HOW TO] Save disk space removing old linux-headers

Even though old kernels have been removed (as described in this preview post), linux-headers packages may still be left behind using precious disk space. Here's how to remove them.

Recovering disk space

Open a terminal window and run:

current_kernel=$(uname -r) && dpkg-query -W -f='${Package}\n' 'linux-headers-[0-9].[0-9][0-9]*' | egrep -v ${current_kernel%-generic} | xargs sudo apt-get remove -y

Running this command I was able to recover a little bit more than 1GB of disk space:

After this operation, 1075 MB disk space will be freed.


Use this command at your own risk. To see what the command will remove just run the first part, without apt-get remove:

current_kernel=$(uname -r) && dpkg-query -W -f='${Package}\n' 'linux-headers-[0-9].[0-9][0-9]*' | egrep -v ${current_kernel%-generic}

No comments:

Post a Comment