command-not-found

Sometimes, you can not use a program because you mistype the command or the program is not installed.
There is a Debian package, command-not-found, which can help you to find the right program.

To install it :

root@localhost:~# apt-get install command-not-found

To use it, put the following line in your own .bashrc :

/etc/zsh_command_not_found

Here is an example. I want to open an .odt document with the gnome-open command. I have mistyped it and here is the suggestion command-not-found can provide :

fool@localhost:~$ gnom-open my_document.odt
No command ‘gnom-open’ found, did you mean:
 Command ‘gnome-open’ from package ‘libgnome2-0’ (main)
gnom-open: command not found

Let’s check the content of the libgnome2-0 package :
root@localhost:~$ dpkg -L libgnome2-0 |grep bin
/usr/bin
/usr/bin/gnome-open

If you want really want to use gnome-open, avoid typing gnom-open as I did just before.

Advertisements

6 thoughts on “command-not-found

    • Here are some more details about command-not-found.
      First of all, you need to run as root ‘/usr/sbin/update-command-not-found’.
      Then, if you are using zsh, add this line to your .zshrc :
      ‘./etc/zsh_command_not_found’

      • You are right. According to BASH manpage, typeset really exists but its option -g do not.
        Here is the content of the file /etc/zsh_command_not_found :

        #!/usr/bin/zsh
        # (c) Zygmunt Krynicki 2007,
        # Licensed under GPL, see COPYING for the whole text
        #
        # This script will look-up command in the database and suggest
        # installation of packages available from the repository

        # Pseudo-namespace cnf_

        function cnf_preexec() {
        typeset -g cnf_command=”${1%% *}”
        }

        function cnf_precmd() {
        (($?)) && [ -n “$cnf_command” ] && [ -x /usr/share/command-not-found/command-not-found ] &}

        typeset -ga preexec_functions
        typeset -ga precmd_functions
        preexec_functions+=cnf_preexec
        precmd_functions+=cnf_precmd

        As a reminder, I just add this line ‘/etc/zsh_command_not_found’ to my .bashrc and It works well :

        fool@localhost:~$ vie /etc/zsh_command_not_found
        No command ‘vie’ found, did you mean:
        Command ‘vile’ from package ‘vile’ (main)
        Command ‘vite’ from package ‘vite’ (main)
        Command ‘vipe’ from package ‘moreutils’ (main)
        Command ‘vic’ from package ‘vic’ (main)
        Command ‘vi’ from package ‘elvis-tiny’ (main)
        Command ‘lie’ from package ‘lie’ (main)
        Command ‘tie’ from package ‘texlive-binaries’ (main)
        Command ‘tie’ from package ‘texlive-extra-utils’ (main)
        Command ‘vpe’ from package ‘texlive-latex-extra’ (main)
        Command ‘vpe’ from package ‘texlive-extra-utils’ (main)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s