What is the difference between `man` and `man (#)`?
Just saw someone referencing man 7 regex
on Stackoverflow. I tried man regex
and got very similar output - there appear to be slight differences.
So what is this magical number 7? Searching man 7 unix
on Google gives me more mysterious results like UNIX(7)...
Solution 1:
About UNIX(7)
To answer your question of "UNIX(7)", this is standard convention of saying "The man page for UNIX in section 7 (miscellaneous)".
To open a page like init(8)
, you would use this command: man 8 init
.
man regex
vs man 7 regex
To answer your question of the 'subtle differences' between man regex
and man 7 regex
:
man
by default opens the page with the lowest section number. In this case, it is section 3 (Library calls). Opening the page from section 7 (Miscellaneous) is quite different.
Pages in different sections address different things, though in this case they are similar, consider apt
:
man -f apt
:
apt (8) - Advanced Package Tool
apt (1) - annotation processing tool
In this example, apt
from section 8 (System administration commands) is completely unrelated to the page from section 1 (Executable programs or shell commands).
For future reference, use man -f PAGE_NAME
to locate all pages with that name in all sections. You can then open a page from the section you want with man SECTION PAGE_NAME
.
Manpage sections
The various page sections are as follows and can be found from man man
:
- Executable programs or shell commands
- System calls (functions provided by the kernel)
- Library calls (functions within program libraries)
- Special files (usually found in
/dev
)- File formats and conventions eg
/etc/passwd
- Games
- Miscellaneous (including macro packages and conventions), e.g.
man(7)
,groff(7)
- System administration commands (usually only for root)
- Kernel routines [Non standard]
Solution 2:
The section numbers
man
will show the manpage from any section, man 7
will show the manpage from section 7. So, here 7 refers to the section of the particular command for which you are looking for the manual page.
A section, if provided, will direct man to look only in that section of the manual.
The sections
See the following table for the section numbers of the manual followed by the types of pages they contain.
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 conventions), e.g. man(7), groff(7)
8: System administration commands (usually only for root). Overviews of various topics, conventions and protocols, character set standards, and miscellaneous other things.
9: Kernel routines [Non standard]
Commands in more than one section
In most of the cases you will want to use the man
command without additional n. However, in some cases a command will appear in more than one section. For example if you issue the command man open
, you get the man page for openvt from section 1. But if you need to see the man page for open as a C (or system call, as per the above table) command, you need to issue man 2 open
.
A very similar example will be man printf
and man 3 printf
. Please issue the commands and see for yourself the difference in output.
Your issue of man 7 unix
(UNIX(7))
So, that UNIX(7) means that it belongs to section 7.
Which section will be shown by default if I do not provide a section number?
The default action is to search in all of the available sections, following a pre-defined order and to show only the first page found, even if page exists in several sections.
How do I know the section number of a command?
Should you need to find out what sections a term/command falls in with man -k
(equivalent to the apropos command). So, man -k printf
will search the short descriptions and manual page names for the keyword printf as regular expression. Print out any matches. (Equivalent to apropos -r printf
). Issue the command, see the ton you get. If need to avoid substring matches, (e.g. it will show sprintf if you run man -k printf
), so you need to use ^term
to limit it, as below,
man -k '^printf'
Printf (3o) - Formatted output functions.
printf (1) - format and print data
printf (3) - formatted output conversion
Related command
A related command is apropos
as indicated above, which searches the manual page names and descriptions. If you are not sure which manual page you are looking for but have a general idea, use this command.