Most of the time you might know what program you need and you open the related man page to find the program’s parameters, but what if you do not know which man page contains the information you are looking for?

Man pages are available everywhere and it’s quite common to open up a man page to check a command’s parameter list or the possible values for one of the parameters, but I came across the need to find out in which man page I could find a specific piece of information.

As an example, lets take the ssh server. When you want to configure the authorized keys as I described in Restrict SSH login using SSH keys to a particular IP address you need to know the format and possible options, but ssh has more then one man page. The ssh client has a couple of different man pages for the different programs it provides and then the ssh server also has more then one man page.

So lets say we want to find out the possible parameters and the format of the authorized_keys file. The man program provides the possibility to search in the man pages to find all pages mentioning a given string. Sadly, man does a case sensitive search which makes it a bit harder to find what you are looking for.

To search all man pages which contain the string “authorized_keys”, run the following command:

$ man -K "authorized_keys" /usr/share/man/man1/ssh-copy-id.1.gz? [ynq] /usr/share/man/man1/ssh-keygen.1.gz? [ynq] /usr/share/man/man1/ssh.1.gz? [ynq] /usr/share/man/man1/slogin.1.gz? [ynq] /usr/share/man/man5/sshd_config.5.gz? [ynq] /usr/share/man/man5/ssh_config.5.gz? [ynq] /usr/share/man/man8/sshd.8.gz? [ynq]

With each man page found you will get the prompt “[ynq]” asking for your action. The three possible answers are:

y: Yes, show the man page. n: No, continue the search. q: Quit, stop the search.

If you hit enter without typing y,n or q the man program assumes “n” and continues the search.

As you can see in the example output above, the found man pages show a number of ssh related man pages where the search string is found, because of the case sensitive nature of the search, this will show only the exact case sensitive match.

If you familiar with the format of man pages, you might have noticed that the big headlines are always upper case. So if we now assume that the authorized_key description is worth a headline, we can search in upper case and will see this result:

$ man -K "AUTHORIZED_KEYS" /usr/share/man/man5/sshd_config.5.gz? [ynq] /usr/share/man/man8/sshd.8.gz? [ynq]

The case sensitive search appears at first to be an annoying limitation, but can be used to your advantage to narrow down the search results.

Read more of my posts on my blog at http://blog.tinned-software.net/.