Remove all unused kernels

As you know, everytime there is an update for the kernel, the new kernel is installed while the old one is not automaticaly uninstalled, after several kernel updates you will find a large list of old kernels in the start grub menu . So if we got no problem with the new installed kernel, we can just delete the old ones as they occupy space which is a wastage of resource.

Well there are multiple ways to find the kernel version:

Print the kernel release with uname:

$ uname -r

Print all the information related to kernel:

$ uname -a

List Linux Kernels with dpkg–debian package manager:

$ sudo dpkg -l | grep linux-headers | grep ii

$ sudo dpkg -l | grep linux-headers | grep ii | awk '{print $3}'

Well following is the magic command which removes unused kernels:

$ 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

There is an extensive use of regular expressions and pipe characters which is very well explained below.

Courtesy:

http://markmcb.com/2013/02/04/cleanup-unused-linux-kernels-in-ubuntu/

https://ubuntugenius.wordpress.com/2011/01/08/ubuntu-cleanup-how-to-remove-all-unused-linux-kernel-headers-images-and-modules/

Change the “device name” in System settings in Ubuntu

Do you want to change your device name as shown in System settings (as shown in the screenshot below) ?

Alright, we will change our device name with the all powerful sed commmand. For your information sed is a special editor for modifying files automatically. If you want to write a program to make changes in a file, sed is the tool to use. For more information on how to use sed refer to

http://www.grymoire.com/Unix/Sed.html#uh-0 .

Solution:

Run the following in your terminal:

sudo sed -i 's/present-host-name/new-host-name/' /etc/hosts
sudo sed -i 's/present-host-name/new-host-name/' /etc/hostname

Now check your present-host-name by cat /etc/hostname or hostname .

EnJoY! 😀

namechange