3

Often if I am doing something in the terminal I will mistype something and enter something unintended.

If I type int as a trivial example, it tells me Command 'int' not found, but there are 18 similar ones.

Not that I need to know these 18 similar commands, but is there any way to find out what these "18 similar ones" are? Whether it be in the terminal or otherwise.

4
  • 1
    Voting to reopen as this is not a duplicate: this question concerns one of the distro-provided "suggest missing package to install" mechanisms, not shell tab completion. Oct 12, 2018 at 6:59
  • Related: How to implement package install suggestion on Debian?
    – user232326
    Oct 12, 2018 at 7:45
  • What OS are you using?
    – user232326
    Oct 12, 2018 at 7:52
  • @Isaac Ubuntu 18.04
    – ofey73
    Oct 12, 2018 at 15:13

1 Answer 1

1

If this is happenning in Ubuntu, askubuntu.com is saying that bash uses /usr/lib/command-not-found which uses Python's CommandNotFound module.

You can see in /usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py the exact lines that are responsible for "but there are X similar ones", they start at line 178 in the CommandNotFound.py file:

if len(mispell_packages)+len(mispell_snaps) > max_alt:
    print("", file=self.output_fd)
    print(_("Command '%s' not found, but there are %s similar ones.") % (word, len(mispell_packages)), file=self.output_fd)
    print("", file=self.output_fd)
    self.output_fd.flush()
    return

Because there is no switch, flag or any option to make CommandNotFound.py return also list of those similar commands, if you really want to know what are those packages you could just edit this part of python file and add two lines that will print content of array with similar commands, instead of just number of things in this array. The lines that are added are lines 4 and 5 in this part of code:

if len(mispell_packages)+len(mispell_snaps) > max_alt:
    print("", file=self.output_fd)
    print(_("Command '%s' not found, but there are %s similar ones.") % (word, len(mispell_packages)), file=self.output_fd)
    for x in range(len(mispell_packaged)):
        print(mispell_packages[x])
    print("", file=self.output_fd)
    self.output_fd.flush()
    return

Now when you save /usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py (you need to edit it as a root), and type int, then you got:

Command 'int' not found, but there are 18 similar ones.
('itd, 'ncl-ncarg', 'universe', '')
('ant, 'ant', 'universe', '')
('inl, 'ioport', 'universe', '')
('inw, 'ioport', 'universe', '')
('tint, 'tint', 'universe', '')
('inc, 'mailutils-mh', 'universe', '')
('inc, 'mmh', 'universe', '')
('inc, 'nmh', 'universe', '')
('nit, 'python-nevow', 'universe', '')
('init, 'systemd-sysv', 'main', '')
('itv, 'python-invoke', 'universe', '')
('itv, 'python3-invoke', 'universe', '')
('cnt, 'open-infrastructure-container-tools', 'universe', '')
('inb, 'ioport', 'universe', '')
('ent, 'ent', 'universe', '')
('ink, 'ink', 'universe', '')
('iyt, 'python3-yt', 'universe', '')
('iat, 'iat', 'universe', '')

The list contains similar commands names (itd, and, inl, inw, tint) and the packages that provides this commands (ncl-ncarg, ant, ioport) and the repo that it comes from (universe, main).

Hope it satisfied your curiosity :) To be honest I was curious too after reading your post.

You must log in to answer this question.

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