2

When I type man regex into a shell, this loads

REGEX(3)                                                     Linux Programmer's Manual                                                     REGEX(3)

NAME
       regcomp, regexec, regerror, regfree - POSIX regex functions

SYNOPSIS
........

when I type man 7 regex I get a different man page

REGEX(7)                                                     Linux Programmer's Manual                                                     REGEX(7)

NAME
       regex - POSIX.2 regular expressions

DESCRIPTION
........

What is happening here?

1

1 Answer 1

4

You can find more about this from man man. The man pages are broken into different sections. This is so things are grouped with like things, and you can have the same name in different spots (like, say, stat which exists in several sections).

The sections, as defined in my old Fedora's man man are:

1   Executable programs or shell commands
2   System calls (functions provided by the kernel)
3   Library calls (functions within program libraries)
4   Special files (usually found in /dev)
5   File formats and conventions eg /etc/passwd
6   Games
7   Miscellaneous  (including  macro  packages and conven‐
       tions), e.g. man(7), groff(7)
8   System administration commands (usually only for root)
9   Kernel routines [Non standard]
9
  • so both these documents are just sections in a larger man document? Commented Sep 26, 2015 at 23:37
  • They are documents for different things. The first one is in section 3, so it is documenting the regex.h library. The second, man 7 regex documents POSIX regular expressions, which are used by many shell commands Commented Sep 26, 2015 at 23:39
  • 1
    I see, so do the writers of the man page for a given program - set a "default" section number that will be loaded when someone simply enters man <program> ? Commented Sep 26, 2015 at 23:43
  • Yes, the section number is generally both included in the man page itself (e.g., the REGEX(3) and REGEX(7) titles in your examples), and that affects where it gets installed. For linux at least they typically they go in /usr/share/man/manX where that X is the section, so /usr/share/man/man3 and /usr/share/man/man7 for your two regex examples. Commented Sep 26, 2015 at 23:55
  • Also, my comment may have misinterpreted your comment question. In general man pages are searched in order, and if you just type man <program> the user will get the first section that has an document for <program>. The user can specify the section they would like to use with the number as in man 7 regex saying to look in section 7, otherwise they're search 1-9 in order and first one "wins". man -a <program> will show all sections that have entries for that document. Also useful is apropos <name> which will give a list of potentially relevent man pages Commented Sep 26, 2015 at 23:58

Not the answer you're looking for? Browse other questions tagged .