You can use this one-liner to automatically clean up all old kernels:

`sudo apt-get purge $( dpkg --list | grep -P -o "linux-(headers|image)-\d\S+" | grep -v $(uname -r | grep -P -o ".+\d") )`

What it does is uninstall (`apt-get purge`) the installed packages (`dpkg --list`) whose names match "linux-headers" or "linux-image" (`grep -P -o "linux-(headers|image)-\d\S+"`), except (`grep -v`) those corresponding to the current kernel version (`uname -r | grep -P -o ".+\d"`)

----
Sources:

* http://www.commandlinefu.com/commands/view/5813/remove-all-unused-kernels-with-apt-ge  
  (for the original inspiration)
* http://askubuntu.com/questions/176322/removing-old-kernel-entries-in-grub#answer-196437  
  (for using apt-get’s “purge” rather than “remove”)
* http://askubuntu.com/questions/18804/what-do-the-various-dpkg-flags-like-ii-rc-mean  
  (for making sure the dpgk entries returned could be safely removed)
* http://stackoverflow.com/questions/6901171/is-d-not-supported-by-greps-basic-expressions  
  (for using PCRE in grep (\d, \S, etc) using the -P option)
* http://superuser.com/questions/274981/return-only-pattern-matched-string-from-grep  
  (for using -o to make grep print only the match)