man-pages - conventions for writing Linux man pages
man [section
] title
This page describes the conventions that should be employed when
writing man pages for the Linux man-pages
project, which
documents the user-space API provided by the Linux kernel and the GNU C
library. The project thus provides most of the pages in Section 2, many
of the pages that appear in Sections 3, 4, and 7, and a few of the pages
that appear in Sections 1, 5, and 8 of the man pages on a Linux system.
The conventions described on this page may also be useful for authors
writing man pages for other projects.
The manual Sections are traditionally defined as follows:
Commands that can be executed by the user from within a shell.
Functions which wrap operations performed by the kernel.
All library functions excluding the system call wrappers (Most of the
libc
functions).
Files found in /dev
which allow to access to devices through
the kernel.
Describes various human-readable file formats and configuration files.
Games and funny little programs available on the system.
Overviews or descriptions of various topics, conventions, and protocols, character set standards, the standard filesystem layout, and miscellaneous other things.
Commands like mount(8), many of which only root can execute.
New manual pages should be marked up using the groff an.tmac package described in man(7). This choice is mainly for consistency: the vast majority of existing Linux manual pages are marked up using these macros.
Please limit source code line length to no more than about 75 characters wherever possible. This helps avoid line-wrapping in some mail clients when patches are submitted inline.
The first command in a man page should be a TH command:
.TH title section date source manual-section
The arguments of the command are as follows:
title
The title of the man page, written in all caps (e.g.,
MAN-PAGES
).
section
The section number in which the man page should be placed (e.g.,
7
).
date
The date of the last nontrivial change that was made to the man page.
(Within the man-pages
project, the necessary updates to these
timestamps are handled automatically by scripts, so there is no need to
manually update them as part of a patch.) Dates should be written in the
form YYYY-MM-DD.
source
The name and version of the project that provides the manual page (not necessarily the package that provides the functionality).
manual-section
Normally, this should be empty, since the default value will be good.
The list below shows conventional or suggested sections. Most manual pages should include at least the highlighted sections. Arrange a new manual page so that sections are placed in the order shown in the list.
NAME LIBRARY [Normally only in Sections 2, 3] SYNOPSIS CONFIGURATION [Normally only in Section 4] DESCRIPTION OPTIONS [Normally only in Sections 1, 8] EXIT STATUS [Normally only in Sections 1, 8] RETURN VALUE [Normally only in Sections 2, 3] ERRORS [Typically only in Sections 2, 3] ENVIRONMENT FILES ATTRIBUTES [Normally only in Sections 2, 3] VERSIONS [Normally only in Sections 2, 3] STANDARDS HISTORY NOTES CAVEATS BUGS EXAMPLES AUTHORS [Discouraged] REPORTING BUGS [Not used in man-pages] COPYRIGHT [Not used in man-pages] SEE ALSO
Where a traditional heading would apply
, please use
it; this kind of consistency can make the information easier to
understand. If you must, you can create your own headings if they make
things easier to understand (this can be especially useful for pages in
Sections 4 and 5). However, before doing this, consider whether you
could use the traditional headings, with some subsections (.SS
)
within those sections.
The following list elaborates on the contents of each of the above sections.
The name of this manual page.
See man(7) for important details of the line(s) that should follow the .SH NAME command. All words in this line (including the word immediately following the "\-") should be in lowercase, except where English or technical terminological convention dictates otherwise.
The library providing a symbol.
It shows the common name of the library, and in parentheses, the name
of the library file and, if needed, the linker flag needed to link a
program against it: (libfoo
[, -lfoo
]).
A brief summary of the command or function's interface.
For commands, this shows the syntax of the command and its arguments (including options); boldface is used for as-is text and italics are used to indicate replaceable arguments. Brackets ([]) surround optional arguments, vertical bars (|) separate choices, and ellipses (...) can be repeated. For functions, it shows any required data declarations or #include directives, followed by the function declaration.
Where a feature test macro must be defined in order to obtain the declaration of a function (or a variable) from a header file, then the SYNOPSIS should indicate this, as described in feature_test_macros(7).
Configuration details for a device.
This section normally appears only in Section 4 pages.
An explanation of what the program, function, or format does.
Discuss how it interacts with files and standard input, and what it produces on standard output or standard error. Omit internals and implementation details unless they're critical for understanding the interface. Describe the usual case; for information on command-line options of a program use the OPTIONS section.
When describing new behavior or new flags for a system call or library function, be careful to note the kernel or C library version that introduced the change. The preferred method of noting this information for flags is as part of a .TP list, in the following form (here, for a new system call flag):
Description of flag...
Including version information is especially useful to users who are constrained to using older kernel or C library versions (which is typical in embedded systems, for example).
A description of the command-line options accepted by a program and how they change its behavior.
This section should appear only for Section 1 and 8 manual pages.
A list of the possible exit status values of a program and the conditions that cause these values to be returned.
This section should appear only for Section 1 and 8 manual pages.
For Section 2 and 3 pages, this section gives a list of the values the library routine will return to the caller and the conditions that cause these values to be returned.
For Section 2 and 3 manual pages, this is a list of the values that
may be placed in errno
in the event of an error, along with
information about the cause of the errors.
Where several different conditions produce the same error, the preferred approach is to create separate list entries (with duplicate error names) for each of the conditions. This makes the separate conditions clear, may make the list easier to read, and allows metainformation (e.g., kernel version number where the condition first became applicable) to be more easily marked for each condition.
The error list should be in alphabetical order
.
A list of all environment variables that affect the program or function and how they affect it.
A list of the files the program or function uses, such as configuration files, startup files, and files the program directly operates on.
Give the full pathname of these files, and use the installation
process to modify the directory part to match user preferences. For many
programs, the default installation location is in /usr/local
,
so your base manual page should use /usr/local
as the base.
A summary of various attributes of the function(s) documented on this page. See attributes(7) for further details.
A summary of systems where the API performs differently, or where there's a similar API.
A description of any standards or conventions that relate to the function or command described by the manual page.
The preferred terms to use for the various standards are listed as headings in standards(7).
This section should note the current standards to which the API conforms to.
If the API is not governed by any standards but commonly exists on other systems, note them. If the call is Linux-specific or GNU-specific, note this. If it's available in the BSDs, note that.
If this section consists of just a list of standards (which it commonly does), terminate the list with a period ('.').
A brief summary of the Linux kernel or glibc versions where a system call or library function appeared, or changed significantly in its operation.
As a general rule, every new interface should include a HISTORY section in its manual page. Unfortunately, many existing manual pages don't include this information (since there was no policy to do so when they were written). Patches to remedy this are welcome, but, from the perspective of programmers writing new code, this information probably matters only in the case of kernel interfaces that have been added in Linux 2.4 or later (i.e., changes since Linux 2.2), and library functions that have been added to glibc since glibc 2.1 (i.e., changes since glibc 2.0).
The syscalls(2) manual page also provides information about kernel versions in which various system calls first appeared.
Old versions of standards should be mentioned here, rather than in STANDARDS, for example, SUS, SUSv2, and XPG, or the SVr4 and 4.xBSD implementation standards.
Miscellaneous notes.
For Section 2 and 3 man pages you may find it useful to include
subsections (SS) named Linux Notes
and
glibc Notes
.
In Section 2, use the heading C library/kernel differences
to mark off notes that describe the differences (if any) between the C
library wrapper function for a system call and the raw system call
interface provided by the kernel.
Warnings about typical user misuse of an API, that don't constitute an API bug or design defect.
A list of limitations, known defects or inconveniences, and other questionable activities.
One or more examples demonstrating how this function, file, or command is used.
For details on writing example programs, see Example programs below.
A list of authors of the documentation or program.
Use of an AUTHORS section is strongly discouraged. Generally, it is better not to clutter every page with a list of (over time potentially numerous) authors; if you write or significantly amend a page, add a copyright notice as a comment in the source file. If you are the author of a device driver and want to include an address for reporting bugs, place this under the BUGS section.
The man-pages
project doesn't use a REPORTING BUGS section
in manual pages. Information on reporting bugs is instead supplied in
the script-generated COLOPHON section. However, various projects do use
a REPORTING BUGS section. It is recommended to place it near the foot of
the page.
The man-pages
project doesn't use a COPYRIGHT section in
manual pages. Copyright information is instead maintained in the page
source. In pages where this section is present, it is recommended to
place it near the foot of the page, just above SEE ALSO.
A comma-separated list of related man pages, possibly followed by other related pages or documents.
The list should be ordered by section number and then alphabetically by name. Do not terminate this list with a period.
Where the SEE ALSO list contains many long manual page names, to
improve the visual result of the output, it may be useful to employ the
.ad l
(don't right justify) and .nh
(don't hyphenate)
directives. Hyphenation of individual page names can be prevented by
preceding words with the string "\%".
Given the distributed, autonomous nature of FOSS projects and their documentation, it is sometimes necessary—and in many cases desirable—that the SEE ALSO section includes references to manual pages provided by other projects.