9

I typed the following in a terminal

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

So Ubuntu knows that "musique" is a program, although it's currently not installed on the machine. However, if I type

$ musiquez
No command 'musiquez' found, did you mean:
 Command 'musique' from package 'musique' (universe)

it knows that there is no such program called "musiquez".

My question is, how does Ubuntu know this? Where is this information stored about what applications can be installed on Ubuntu?

2 Answers 2

9

This feature is provided by the command-not-found( Its function is to suggest alternatives and corrections in case of mistyping etc. ) package. Ubuntu installs it by default.

how does it work?

The way it works is through the command_not_found_handle() function in bash. bash provides a hook which is basically a function that is invoked when a command is not found.


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.

enter image description here

4

A pair of packages, command-not-found and command-not-found-data, are what makes this feature work.

command-not-found is simply a handler for the command_not_found_handle() bash function; it searches through the data about the mapping between commands and packages provided by command-not-found-data.

1
  • I would assume that command-not-found then checks through the local cache of the repositories that is made every time a user runs sudo apt-get update.
    – nerdwaller
    Commented Jul 11, 2013 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .