8

So, when a command is not found, by what means is the "did you mean:" list populated? What program finds these alternate commands? What is the meaning of: "(main), (universe)..."? Can I change which program finds these?

3
  • 1
    Are you asking what programs offer this functionality or which does it in your case? If the latter, you provided too little information. What shell do you use, for start?
    – techraf
    Commented Apr 26, 2016 at 2:41
  • I'm using bash but I really just mean in the most general case. What programs provide this and is there a fairly consistent way to determine the program in most shells?
    – user167562
    Commented Apr 26, 2016 at 2:47
  • It also depends greatly on what flavor/distro of Unix/Linux you're using as to how the feature is implemented.
    – Randall
    Commented Sep 22, 2017 at 19:28

4 Answers 4

5

For bash, its behavior is governed by the shell function command_not_found_handle (See man bash).

To see what behavior is defined by that function, you can issue:

declare -p -f command_not_found_handle

You can change which program is used by redefining the command_not_found_handle function.

In Debian-based distros (including Ubuntu), the package command-not-found is commonly installed, and available as /usr/lib/command-not-found From the link:

Suggest installation of packages in interactive bash sessions

This package will install handler for command_not_found that looks up programs not currently installed but available from the repositories.

See also:

2

If you look at contents of /etc/apt/sources.list it will have the format

#Archive type  Repository URL                   Distribution Component
 deb           http://archive.ubuntu.com/ubuntu precise      main

Archive type

The first word on each line, deb or deb-src, indicates the type of archive. Deb indicates that the archive contains binary packages (deb), and so on.

Repository URL

The next entry on the line is a URL to the repository that you want to download the packages from.

Distribution

The 'distribution' can be either the release code name / alias (wheezy, jessie, stretch, sid) or the release class (oldstable, stable, testing, unstable) respectively.

What is the meaning of: "(main), (universe)..."?

Component

main consists of DFSG-compliant packages, contrib packages contain DFSG-compliant software, but have dependencies not in main,non-free contains software that does not comply with the DFSG and so on. A tip - Check one of the repository urls,it should have a folder with the name of component.

The package managers say apt will have a database which contains a list of all packages in the repositories and it is smart enough to give you suggestions.

Your package manager may be on eof dpkg(eg Debian, Ubuntu etc), apt(eg Debian, Ubuntu etc), now obsolete rpm(eg older Redhat versions and newer ones don't kick it off for compatibility reasons),yum(eg. Fedora,CentOS),dnf - dentrified yum (eg.New Fedora releases) and so on. For a more comlpete list check this. You might even see are multiple package managers in one distribution. For example in Ubuntu, you may see dpkg which feeds /etc/apt/sources/list.

So when you type

cleaq

It may say

cleaq: no command found. Did you mean clean.

by what means is the "did you mean:" list populated?

This involves a pattern match with the packages in the your package manager database.

This database is updated when you do do an apt-get update

Not sure about

Can I change which program finds these?

though. I believe this is a feature which cannot be changed. Not so sure though

Reference : Debian SourceList

2
  • 1
    @vondirac : Yes sources.list is inside the /etc/apt. See the edit.. Well, in general you can say your package manager maintains this list for you and you package manager can be apt(in case of Debian, Ubuntu etc), rpm(Redhat and its clones),yum(eg. Fedora,CentOS) and dnf(New Fedora releases)
    – sjsam
    Commented Apr 26, 2016 at 3:12
  • You can improve this answer with reference to some Ubuntu doco.
    – JdeBP
    Commented Dec 28, 2016 at 12:35
-1

This is not a standard feature of Linux shells. There are at least two possibilities:

  • zsh is maintaining its own suggestion list
  • project thefuck offers another one
-1

police tisn No command police found, did you mean: Command polipo in package polipo Command ionice in package util-linux $

2

You must log in to answer this question.