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
  • 2
    How about elinks 'g:linux search for file'? Jan 9 '18 at 15:21
  • CTRL+R followed by some consecutive characters will search your command history for a previously used command or string. Jan 15 at 12:07
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...

3
  • Thanks for your answer! My Problem with this is that there is no man page for "find". Jan 9 '18 at 10:03
  • Which Linux distro are you using? There should be a manpage for find on all modern distros.
    – dr_
    Jan 9 '18 at 10:28
  • Termux on Android which uses bash. There are man pages for other commands (e.g. "ssh"..). Jan 9 '18 at 10:35
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, deepmod)

man -k mod | cut -d ' ' -f 1 | grep 'mod$'
New contributor
Abdullah is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 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) Jan 15 at 8: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 at 16:08
  • Sorry typo. That's compgen. See info bash compgen Jan 15 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.