Disabling default package checking for unknown Ubuntu commands

Posted on December 21, 2007

Ubuntu comes with a nifty script installed that is run when you type a non-existing command. It checks to see if there is a package that will provide this command and if there is it will show you a nice message how to install it. I do like this functionality but now that my system has pretty much all I need, the slight delay caused by running the script has become annoying. I could just do a 'sudo apt-get remove command-not-found' but I would still like to able to quickly check if there is a package providing a command if I want to. A few lines added to my ~/.bashrc can do exactly that:

command_not_found_handle() {
  return 127
}
alias check-command=/usr/lib/command-not-found

This redefines the command_not_found_handle defined in /etc/bash.bashrc to just display an error message and gives me check-command to check if a package is available for a command. And finally again 'l s-l' will barf at me instantly again :). And:

$ check-command aatv
The program 'aatv' is currently not installed.  You can install it by typing:
sudo apt-get install aatv

$ check-command emacs
Command 'emacs' is available in '/usr/bin/emacs'