|MAN-PAGES(7)||Linux Programmer's Manual||MAN-PAGES(7)|
NAME¶man-pages - conventions for writing Linux man pages
SYNOPSIS¶man [section] title
DESCRIPTION¶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.
Sections of the manual pages¶The manual Sections are traditionally defined as follows:
- 1 User commands (Programs)
- Those commands that can be executed by the user from within a shell.
- 2 System calls
- Those functions which wrap operations performed by the kernel.
- 3 Library calls
- All library functions excluding the system call wrappers (Most of the libc functions).
- 4 Special files (devices)
- Files found in /dev which allow to access to devices through the kernel.
- 5 File formats and configuration files
- Describes various human-readable file formats and configuration files.
- 6 Games
- Games and funny little programs available on the system.
- 7 Overview, conventions, and miscellaneous
- Overviews or descriptions of various topics, conventions and protocols, character set standards, the standard filesystem layout, and miscellaneous other things.
- 8 System management commands
- Commands like mount(8), many of which only root can execute.
Macro package¶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.
Conventions for source file layout¶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.
Title line¶The first command in a man page should be a TH command:
- The title of the man page, written in all caps (e.g., MAN-PAGES).
- The section number in which the man page should be placed (e.g., 7).
- 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.
- The source of the command, function, or system call.
- The title of the manual (e.g., for Section 2 and 3 pages in the man-pages package, use Linux Programmer's Manual).
Sections within a manual page¶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 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 VERSIONS [Normally only in Sections 2, 3] ATTRIBUTES [Normally only in Sections 2, 3] CONFORMING TO NOTES BUGS EXAMPLE 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 name of this manual page.
- A brief summary of the command or function's interface.
- Configuration details for a device.
- An explanation of what the program, function, or format
- XYZ_FLAG (since Linux 3.7)
- 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.
- EXIT STATUS
- A list of the possible exit status values of a program and
the conditions that cause these values to be returned.
- RETURN VALUE
- 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.
- 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
- A summary of various attributes of the function(s) documented on this page. See attributes(7) for further details.
- A brief summary of the Linux kernel or glibc versions where
a system call or library function appeared, or changed significantly in
- CONFORMING TO
- A description of any standards or conventions that relate
to the function or command described by the manual page.
- Miscellaneous notes.
- 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.
- A list of authors of the documentation or program.
- SEE ALSO
- A comma-separated list of related man pages, possibly
followed by other related pages or documents.
- 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 "\%".
STYLE GUIDE¶The following subsections describe the preferred style for the man-pages project. For details not covered below, the Chicago Manual of Style is usually a good source; try also grepping for preexisting usage in the project source tree.
Use of gender-neutral language¶As far as possible, use gender-neutral language in the text of man pages. Use of "they" ("them", "themself", "their") as a gender-neutral singular pronoun is acceptable.
Formatting conventions for manual pages describing functions¶For manual pages that describe command (typically in Sections 1 and 8), the arguments are always specified using italics, even in the SYNOPSIS section.
Formatting conventions for manual pages describing functions¶For manual pages that describe functions (typically in Sections 2 and 3), the arguments are always specified using italics, even in the SYNOPSIS section, where the rest of the function is specified in bold: int myfunction(int argc, char **argv); Variable names should, like argument names, be specified in italics.
.BR fcntl ()(Using this format, rather than the use of "\fB...\fP()" makes it easier to write tools that parse man page source files.)
Formatting conventions (general)¶Filenames (whether pathnames, or references to header files) are always in italics (e.g., <stdio.h>), except in the SYNOPSIS section, where included files are in bold (e.g., #include <stdio.h>). When referring to a standard header file include, specify the header file surrounded by angle brackets, in the usual C way (e.g., <stdio.h>). Special macros, which are usually in uppercase, are in bold (e.g., MAXINT). Exception: don't boldface NULL. When enumerating a list of error codes, the codes are in bold (this list usually uses the .TP macro).
man 7 man-pages
If the command is short, then it can be included inline in the text, in italic format, for example, man 7 man-pages. In this case, it may be worth using nonbreaking spaces ("\ ") at suitable places in the command. Command options should be written in italics (e.g., -l). Expressions, if not written on a separate indented line, should be specified in italics. Again, the use of nonbreaking spaces may be appropriate if the expression is inlined with normal text.
Any reference to another man page should be written with the name in bold, always followed by the section number, formatted in Roman (normal) font, without any separating spaces (e.g., intro(2)). The preferred way to write this in the source file is:
$ date Thu Jul 7 13:01:27 CEST 2016
.BR intro (2)(Including the section number in cross references lets tools like man2html(1) create properly hyperlinked pages.)
Spelling¶Starting with release 2.59, man-pages follows American spelling conventions (previously, there was a random mix of British and American spellings); please write all new pages and patches according to these conventions.
- American English tends to use the forms "backward", "upward", "toward", and so on rather than the British forms "backwards", "upwards", "towards", and so on.
BSD version numbers¶The classical scheme for writing BSD version numbers is x.yBSD, where x.y is the version number (e.g., 4.2BSD). Avoid forms such as BSD 4.3.
Capitalization¶In subsection ("SS") headings, capitalize the first word in the heading, but otherwise use lowercase, except where English usage (e.g., proper nouns) or programming language requirements (e.g., identifier names) dictate otherwise. For example:
.SS Unicode under Linux
Indentation of structure definitions, shell session logs, and so on¶When structure definitions, shell session logs, and so on are included in running text, indent them by 4 spaces (i.e., a block enclosed by .in +4n and .in).
Preferred terms¶The following table lists some preferred terms to use in man pages, mainly to ensure consistency across pages.
|Epoch||epoch||For the UNIX Epoch (00:00:00, 1 Jan 1970 UTC)|
|lowercase||lower case, lower-case|
|privileged port||reserved port, system port|
|real-time||realtime, real time|
|saved set-group-ID||saved group ID, saved set-GID|
|saved set-user-ID||saved user ID, saved set-UID|
|superuser||super user, super-user|
|superblock||super block, super-block|
|uppercase||upper case, upper-case|
Terms to avoid¶The following table lists some terms to avoid using in man pages, along with some suggested alternatives, mainly to ensure consistency across pages.
|32bit||32-bit||same for 8-bit, 16-bit, etc.|
|current process||calling process||A common mistake made by kernel programmers when writing man pages|
|manpage||man page, manual page|
|minus infinity||negative infinity|
|plus infinity||positive infinity|
Trademarks¶Use the correct spelling and case for trademarks. The following is a list of the correct spellings of various relevant trademarks that are sometimes misspelled:
NULL, NUL, null pointer, and null character¶A null pointer is a pointer that points to nothing, and is normally indicated by the constant NULL. On the other hand, NUL is the null byte, a byte with the value 0, represented in C via the character constant '\0'.
Hyperlinks¶For hyperlinks, use the .UR/.UE macro pair (see groff_man(7)). This produces proper hyperlinks that can be used in a web browser, when rendering a page with, say:
BROWSER=firefox man -H pagename
Use of e.g., i.e., etc., a.k.a., and similar¶In general, the use of abbreviations such as "e.g.", "i.e.", "etc.", "a.k.a." should be avoided, in favor of suitable full wordings ("for example", "that is", "and so on", "also known as").
Em-dashes¶The way to write an em-dash—the glyph that appears at either end of this subphrase—in *roff is with the macro "\(em". (On an ASCII terminal, an em-dash typically renders as two hyphens, but in other typographical contexts it renders as a long dash.) Em-dashes should be written without surrounding spaces.
Hyphenation of attributive compounds¶Compound terms should be hyphenated when used attributively (i.e., to qualify a following noun). Some examples:
Hyphenation with multi, non, pre, re, sub, and so on¶The general tendency in modern English is not to hyphenate after prefixes such as "multi", "non", "pre", "re", "sub", and so on. Manual pages should generally follow this rule when these prefixes are used in natural English constructions with simple suffixes. The following list gives some examples of the preferred forms:
Real minus character¶Where a real minus character is required (e.g., for numbers such as -1, or when writing options that have a leading dash, such as in ls -l), use the following form in the man page source:
Character constants¶To produce single quotes that render well in both ASCII and UTF-8, use the following form for character constants in the man page source:
Example programs and shell sessions¶Manual pages may include example programs demonstrating how to use a system call or library function. However, note the following:
- Example programs should be written in C.
- An example program is necessary and useful only if it demonstrates something beyond what can easily be provided in a textual description of the interface. An example program that does nothing other than call an interface usually serves little purpose.
- Example programs should be fairly short (preferably less than 100 lines; ideally less than 50 lines).
- Example programs should do error checking after system calls and library function calls.
- Example programs should be complete, and compile without warnings when compiled with cc -Wall.
- Where possible and appropriate, example programs should allow experimentation, by varying their behavior based on inputs (ideally from command-line arguments, or alternatively, via input read by the program).
- Example programs should be laid out according to Kernighan
and Ritchie style, with 4-space indents. (Avoid the use of TAB characters
in source code!) The following command can be used to format your source
code to something close to the preferred style:
indent -npro -kr -i4 -ts4 -sob -l72 -ss -nut -psl prog.c
- For consistency, all example programs should terminate
using either of:
- If there is extensive explanatory text before the program
source code, mark off the source code with a subsection heading Program
source, as in:
.SS Program source
- Place the session log above the source code listing
- Indent the session log by four spaces.
- Boldface the user input text, to distinguish it from output produced by the system.
EXAMPLE¶For canonical examples of how man pages in the man-pages package should look, see pipe(2) and fcntl(2).
SEE ALSO¶man(1), man2html(1), attributes(7), groff(7), groff_man(7), man(7), mdoc(7)
COLOPHON¶This page is part of release 4.10 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.