Deleting all older kernels on an Ubuntu server apt-get command

Fig.01: Deleting all older kernels on an Ubuntu server

Fig.01: Deleting all older kernels on an Ubuntu server

You just need to type the following command to delete all older kernel safely on an Ubuntu Linux server:
$ sudo apt --purge autoremove
OR
$ sudo apt-get --purge autoremove
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-3.13.0-91* linux-headers-3.13.0-91-generic*
  linux-headers-3.13.0-92* linux-headers-3.13.0-92-generic*
  linux-image-3.13.0-91-generic* linux-image-3.13.0-92-generic*
0 upgraded, 0 newly installed, 6 to remove and 0 not upgraded.
After this operation, 240 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 156176 files and directories currently installed.)
Removing linux-headers-3.13.0-91-generic (3.13.0-91.138) ...
Removing linux-headers-3.13.0-91 (3.13.0-91.138) ...
Removing linux-headers-3.13.0-92-generic (3.13.0-92.139) ...
Removing linux-headers-3.13.0-92 (3.13.0-92.139) ...
Removing linux-image-3.13.0-91-generic (3.13.0-91.138) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/last-good-boot 3.13.0-91-generic /boot/vmlinuz-3.13.0-91-generic
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-91-generic /boot/vmlinuz-3.13.0-91-generic
update-initramfs: Deleting /boot/initrd.img-3.13.0-91-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-91-generic /boot/vmlinuz-3.13.0-91-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-3.13.0-95-generic
Found kernel: /vmlinuz-3.13.0-93-generic
Found kernel: /vmlinuz-3.13.0-92-generic
Found kernel: /memtest86+.bin
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done
 
Purging configuration files for linux-image-3.13.0-91-generic (3.13.0-91.138) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-91-generic /boot/vmlinuz-3.13.0-91-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-91-generic /boot/vmlinuz-3.13.0-91-generic
Removing linux-image-3.13.0-92-generic (3.13.0-92.139) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/last-good-boot 3.13.0-92-generic /boot/vmlinuz-3.13.0-92-generic
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-92-generic /boot/vmlinuz-3.13.0-92-generic
update-initramfs: Deleting /boot/initrd.img-3.13.0-92-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-92-generic /boot/vmlinuz-3.13.0-92-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /vmlinuz-3.13.0-95-generic
Found kernel: /vmlinuz-3.13.0-93-generic
Found kernel: /memtest86+.bin
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done
 
Purging configuration files for linux-image-3.13.0-92-generic (3.13.0-92.139) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-92-generic /boot/vmlinuz-3.13.0-92-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-92-generic /boot/vmlinuz-3.13.0-92-generic
root@backup2:~#

Examples and usage: Safely Remove / Delete Old Linux Kernel from a Linux Server