<

How to suppress older kernels in Ubuntu in one command line

Published on
9,843 Points
3,043 Views
3 Endorsements
Last Modified:
Approved
After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates.

All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that with a bad kernel, you can't boot your system. So the update process doesn't erase the previous version of linux-image, and the boot loader (GRUB in the case of Ubuntu), gives you the choice at boot time to choose into which kernel you want to boot.

As the list of older images begins to grow, and in order to save room on your disk drive, you may be interested to erase the older versions, and if possible, with only one command line.

The command shell is able to do that. Just open a terminal (Applications > Accessories > Terminal), copy the line below and past it at the prompt of your terminal:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y remove

And that's it. You will be asked to enter your password for running some command that must be executed as super user.

You will find a detailed explanation of the logic behind this at http://tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/ 

This works on all Ubuntu and Debian systems, but you can adapt it for Fedora or RedHat by changing the command "apt-get -y remove" by its equivalent, which is "yum".
3
Comment
2 Comments
 
LVL 10

Author Comment

by:Pierre François
I wish to add two ideas:

This command erases all the kernels excepted the running one. Before running this command, be sure you are running the most recent kernel at that moment, rebooting first if necessary. Anyway, the script is prudent enough to avoid erasing the current running kernel, so don't be afraid.
If you are happy with this command line, you can save it as an executable shell file in the bin directory of your home directory.
0
 

Expert Comment

by:cigtoxdoc
There is a much easier way.  Ubuntu Tweak 0.8.7 (http://ubuntu-tweak.com/).  It works even with 15.10.  It also has one major feature I find very useful as I use PDF Studio Pro 10 (full Adobe equivalent) for all my PDF work.  Ubuntu Tweak lets you set file associations that you cannot set otherwise, except with some difficulty.

John
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Join & Write a Comment

How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month