0

I want to search for bash commands in the bash itself. When I forget the name of a command I want a fast way to find it. For example "search for file" should suggest "find".

2 Answers2

4

The closest thing you can get is via one of these commands:

man -k search
apropos search

These will return all manpages whose description contains the word "search".

You can restrict the search to pages in section 1 (user commands) and 8 (admin commands) with the (non-standard) -s option:

man -ks1,8 search

That would omit pages about programming APIs or concepts, file formats...

dr_
  • 29,602
1

As @dr_ suggested using man -k search works well, but sometimes it gives a long list of results along with the description. So, if you want to display results nicely you can use cut and list only the name of commands as follows

Let say we want to find *mod (usermod, groupmod, depmod)

man -k mod | cut -d ' ' -f 1 | grep 'mod$'
  • man -k mod | awk '$1 ~ /mod$/' (or just man -k 'mod$') would probably be more useful (if only because many of those will be about things other than commands). See also type -m '*mod' in zsh or comgen -c | grep 'mod$' in bash. Also man -s1,6,8 -k 'mod$' to restrict the search to sections 1, 6 and 8 (at least with the man from mandb) – Stéphane Chazelas Jan 15 '22 at 08:43
  • @StéphaneChazelas you are right. Your suggestions also worked well except comgen -c | grep 'mod$'. (comgen: command not found) Do you think it comes builtin or do we have to install it? – Abdullah Jan 15 '22 at 16:08
  • Sorry typo. That's compgen. See info bash compgen – Stéphane Chazelas Jan 15 '22 at 19:21