How to search for all the man files that contain certain keyword?
I want to learn how to search for a file by giving the content within it as a parameter. I can then apply the solution to search for commands contributed by Richard Stallman (through man pages).
Solution 1:
From man man
:
-K, --global-apropos
Search for text in all manual pages. This is a brute-force
search, and is likely to take some time; if you can, you should
specify a section to reduce the number of pages that need to be
searched. Search terms may be simple strings (the default), or
regular expressions if the --regex option is used.
-w, --where, --location
Don't actually display the manual pages, but do print the
location(s) of the source nroff files that would be formatted.
Combined:
man -wK 'Richard M Stllman'
Though manpages typically have just Richard Stallman
, with a variable amount of space between the two words, so a regex might be appropriate:
--regex
Show all pages with any part of either their names or their
descriptions matching each page argument as a regular
expression, as with apropos(1). Since there is usually no
reasonable way to pick a "best" page when searching for a
regular expression, this option implies -a.
So:
man --regex -wK 'Richard *Stallman'
Solution 2:
This command will show you the filenames of man files that contain the keyword Stallman
:
zgrep -l Stallman /usr/share/man/man?/*
Output in my 15.10 begins with:
/usr/share/man/man1/cat.1.gz
/usr/share/man/man1/comm.1.gz
/usr/share/man/man1/ctags.1.gz
/usr/share/man/man1/ctags.emacs24.1.gz
Then, you can browse as usual, with man cat
, man comm
, etc.
Solution 3:
This method does not search the entire manpages for a keyword, but only each manpage's title and short description. It will not be enough in your case, but useful to quickly look up something. If it does not return the desired results, you have to use @philsf's answer.
You can use the apropos
command to quickly search all installed manpages' title and description for a keyword:
$ apropos chat
chat (8) - Automated conversational script with a modem
chattr (1) - change file attributes on a Linux file system
empathy (1) - GNOME multi-protocol chat and call client
You can display a known manpage's description using whatis
:
$ whatis empathy
empathy (1) - GNOME multi-protocol chat and call client
As I said, this method will not search the entire manpage body, therefore apropos Stallman
returns nothing...