How Ubuntu's command suggestion feature works?
Have you ever wondered how Ubuntu gives you suggestions when you enter a wrong command name on a terminal? This feature is a great way to quickly figure out the error and even helps to find out the package that provide a particular tool. This task is taken care of by the command_not_found_handle() function in /etc/bash.bashrc.
This is how command_not_found_handle is defined on Ubuntu 10.10, Maverick Meerkat.
[shredder12]$ type command_not_found_handle
command_not_found_handle is a function
if [ -x /usr/lib/command-not-found ]; then
/usr/bin/python /usr/lib/command-not-found -- $1;
if [ -x /usr/share/command-not-found ]; then
/usr/bin/python /usr/share/command-not-found -- $1;
If you notice the output above, command_not_found_handle looks for /usr/lib/command-not-found and executes it as a python script otherwise returns error 127.
If you are more curious, open the /usr/lib/command-not-found file and take a look at the script. It works using the python module CommandNotFound.
So, now you know how Ubuntu takes care of your terminal errors .