Remove unused kernel header files in Ubuntu

Straightforward, constant updating is the key to have a fresh and bleeding edge Ubuntu system. However, for those of you who are strapped for disk space – for instance if you are hosting multiple operating systems on one drive – “useless” files can eat up quite a big chunck of your available megabytes. Numerous ways exist to erase and purge unnecessary files and packages, but for the most part they all omit one crucial step: removing those kernel headers that have remained on your drive since downloading and using them for the first time.

In order to remove ALL but the one you are currently using (check it by entering “uname -r” in the Terminal), hit up a Terminal and issue the following command in one line:

 
sudo apt-get purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')
 

The APT daemon will ask you whether you’d like to remove the headers and stuff – be sure to double check your current kernel’s version. That’s all folks 🙂

 

Source is available by clicking here, as this is a repost/reblog of the real thing.

About the author

Gábor Hargitai

View all posts