[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.

Disclaimer

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}

Comments

Popular posts from this blog

[FIX] VLC is unable to open the MRL (smb://)

[SOLVED] apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName on Xubuntu

Add items to Xfce Applications Menu