Score:2

Why can't Ubuntu use the command-not-found command?

kn flag

I use Ubuntu 22.04, and I found that Ubuntu has preinstalled the command-not-found package, but the command-not-found command cannot be used.

Because Debian's command-not-found package provides the command-not-found command that looks up programs not currently installed but available from the repositories.

May I ask whether Ubuntu has modified this package?

Any answer is greatly appreciated

muru avatar
us flag
What do you mean by "cannot be used"? How did you try to use it?
vn flag
Yes, Canonical modified the package to add its snap thing. I mentioned [here](https://askubuntu.com/a/1384366/349837) a way to remove it
Score:2
hr flag

The command itself (actually it's an executable Python script) lives in /usr/lib/, which is not usually in a user's PATH. But you can certainly run it if you wish, e.g.

$ /usr/lib/command-not-found cpufetch
Command 'cpufetch' not found, but can be installed with:
sudo snap install cpufetch  # version 1.04, or
sudo apt  install cpufetch  # version 1.01+git20211208+40b13bc-2
See 'snap info cpufetch' for additional versions.

However it's typically run automagically by the bash shell, via its command_not_found_handle hook function:

$ declare -f -p command_not_found_handle
command_not_found_handle () 
{ 
    if [ -x /usr/lib/command-not-found ]; then
        /usr/lib/command-not-found -- "$1";
        return $?;
    else
        if [ -x /usr/share/command-not-found/command-not-found ]; then
            /usr/share/command-not-found/command-not-found -- "$1";
            return $?;
        else
            printf "%s: command not found\n" "$1" 1>&2;
            return 127;
        fi;
    fi
}
Score:1
us flag

command-not-found is not a command to be used. If you enter a command corresponding to a package which is not installed, Ubuntu will offer you to install the package.

For example, if you write cpufetch, Ubuntu will offer you to install it with

sudo apt install cpufetch
raj avatar
cn flag
raj
Sometimes you may need a "clean" way (ie. without typing a wrong command on a command line) to display what package provides a particular command, so there may be a few rare cases when you'd actually want to use the `command-not-found` command.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.