Search which man sections contain a given entry

2

1

On Linux (or any other OS that uses the man tool), there are typically several sections of the manual. Often, a given entry (such as echo or printf) exists in multiple sections, but not all of them. Is there a simple way to check which sections of the manual that entry can be found in?

Obviously, one can try man [section] [entry] and just run through every section in the manual, but honestly, I'm not even sure what the complete list of sections is (or how to find that definitively), and I'm looking for something a little less brute-force.

patrickvacek

Posted 2014-01-10T20:28:11.307

Reputation: 175

Answers

1

Try whatis (eg, whatis printf). The sections of man are not random. See Wikipedia: Man page. For example, section 2 contains only System calls while section 3 only contains C Library calls. There is a version of printf for use on the command line so it is located in section 1. But there is also one in the C Library so that is located in section 3.

You will have to create the whatis database first with makewhatis -w (on Cygwin, it is in /usr/sbin).

Peon

Posted 2014-01-10T20:28:11.307

Reputation: 771

Thanks for the tip! Unfortunately, whatis returns either nothing appropriate or manpath is null (despite that it isn't) on the systems I'm using right now. And I've read that Wikipedia page before, but as it makes clear, different systems have different sections, and I'm not sure how to check which ones are present except by brute force. – patrickvacek – 2014-01-10T21:20:08.663

1@patrickvacek, have to create the whatis database first with makewhatis -w (on Cygwin, it is in /usr/sbin). – Peon – 2014-01-10T21:37:38.670

Oops, now it makes so much more sense. Thanks! – patrickvacek – 2014-01-10T22:08:48.303

3

These work with FreeBSD man, with the man from Linux distributions and the likes of Debian Hurd, and even with Cygwin man:

man -a -f ${entry}

or, more cryptically but perhaps more usefully in shell scripts,

man -a -w ${entry}

Of course, you must have your whatis database populated correctly. With Cygwin, this doesn't happen out of the box, unlike with FreeBSD, Debian, and the like. One has to run makewhatis.

JdeBP

Posted 2014-01-10T20:28:11.307

Reputation: 23 855

The latter (man -a -w) works beautifully for me with cygwin, but I'm still having trouble with my Linux systems... although I think that may be specific to those systems. But even on cygwin, the former (man -a -f) yields nothing appropriate (its own words). – patrickvacek – 2014-01-10T21:31:25.410

You didn't ask about Cygwin, and I didn't answer about Cygwin. Cygwin's man is a different beast. If you want Cygwin answers, it's best not to start a question with "On Linux" and tag it as [Linux]. – JdeBP – 2014-01-10T21:48:07.897

Sorry for any confusion; I only mentioned Cygwin because I turned to it after my lack of success with Linux (CentOS) systems. My question remains focused on Linux. I just tried the commands on an Ubuntu system and they worked beautifully. (And after creating the whatis database in Cygwin, even the man -a -f works, too.) Thanks! – patrickvacek – 2014-01-11T03:37:12.497