A A
RSS

How to disable command-not-found in Ubuntu

Fri, Jun 4, 2010

Tweet this!

If you make a typo on the command line in Ubuntu, or if you type the name of a command that doesn’t exist, the system will automatically provide you with a list of commands that are similar to what you entered; or, if the command exists but the package it belongs to is not installed, it will provide you with the name of the package that you need to install to get that command.  However, this feature does slow down the shell, and if you use the command line often, it does get to be annoying.  This article will show you how to disable the command suggestion feature in Ubuntu.

8SQHVUP4GCZ8

Example Output of the Command Suggestion Feature

Just so we’re all on the same page, this is the feature I am going to disable:

This is what happens if you make a typo typing a command; it will try to give you a “command spell check”:

root@spirit:/usr/share# picco
No command ‘picco’ found, did you mean:
Command ‘pico’ from package ‘nano’ (main)
Command ‘pico’ from package ‘alpine-pico’ (universe)
picco: command not found

Or, if you type a command that does exist, but is not installed:

root@spirit:/usr/share# vim
The program ‘vim’ can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-gtk
* vim-nox
Try: apt-get install <selected package>
Disabling the Command Suggestion Feature in Ubuntu

There are two things you need to do to disable this feature.  The first is to remove the package that provides the feature, and the second is to do a quick workaround to bypass a bug which makes the package removal only partially complete.

Step one: Remove the command-not-found package.

sudo apt-get remove command-not-found

If you try executing a non-existent command now, you’ll see that you’ll get a Python error, as shown below.  This is because of the bug referenced above.

root@spirit:/usr/share# picco
/usr/bin/python: can’t find ‘__main__.py’ in ‘/usr/share/command-not-found’

Step Two: To work around this bug, we simply need to run the following command:

sudo mv /usr/share/command-not-found /usr/share/command-not-found.bak

You need to restart your shell for the change to take affect, but once you open a new terminal you’ll see the classic “command not found” bash error:

root@spirit:/home/jdeprizi# picco
bash: picco: command not found
Re-Enabling the Command Suggestion Feature

If, in the future, you decide that you want to re-enable the command suggestion, here is how:

sudo apt-get install command-not-found
sudo mv /usr/share/command-not-found.bak /usr/share/command-not-found

That’s all it takes — just close your terminal and open it again, and you will have the command suggestion available again.

7 Responses to “How to disable command-not-found in Ubuntu”

  1. Chris Goldman says:

    You can do the same thing more simply, in one step:

    sudo apt-get remove command-not-found command-not-found-data

    The “/usr/share/command-not-found” directory is in the “command-not-found-data” package, which is a dependency of the “command-not-found” package.

  2. Benoit says:

    Well. Removing a package from a system for a single user’s sake is an obvious sign of dictatorship.

    Just add the following line in your ~/.bashrc:

    unset command_not_found_handle

    • brankovic says:

      Not so well, it doesnt work. At least on my ubuntu 10 command

      env | grep -i ‘command\|found\|handle’

      gives nothing. But i agree, there must be a way to just disable the feature without resorting to uninstall.

      • rcaron says:

        command_not_found_handle is implemented as a Bash shell function, but the function is not exported. To check to see if you have it enabled, run

        set | grep “command_not_found_handle”

    • Neal Clark says:

      not when it’s the dumbest package ever

  3. jpd says:

    i did this, but then commands (like mc)
    which is not installed, but exists
    gave no errors

Leave a Reply

Weekly Poll

What's the best Linux distribution for desktops?

View Results

Loading ... Loading ...

Search TechThrob

Advertisement