Remove all unused kernel from /boot partition

Everytime we update the kernel, ubuntu does not remove the old kernel. If you always update your kernel you'll have a bunch of unused kernel in boot loader. It's not only make your boot loader looks dirty but also waste a disk space, especially if you have separate /boot partition.

/boot partition is needed when you have LVM or raid partition as a part of system. As i read it from ubuntugenius there is a one line command to clean up your old kernel. Here it is.

$ 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