]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/man-pages.7
ffix
[thirdparty/man-pages.git] / man7 / man-pages.7
1 .\" (C) Copyright 1992-1999 Rickard E. Faith and David A. Wheeler
2 .\" (faith@cs.unc.edu and dwheeler@ida.org)
3 .\" and (C) Copyright 2007 Michael Kerrisk <mtk-manpages@gmx.net>
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" 2007-05-30 created by mtk, using text from old man.7 plus
26 .\" rewrites and additional text.
27 .\"
28 .TH MAN-PAGES 7 2007-05-30 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 man-pages \- conventions for writing Linux man pages
31 .SH SYNOPSIS
32 .B man
33 .RI [ section ]
34 .I title
35 .SH DESCRIPTION
36 This page describes the conventions that should be employed
37 when writing man pages for the Linux \fIman-pages\fP project,
38 which comprises Sections 2, 3, 4, 5, and 7 of the Linux manual pages.
39 The conventions described on this page may also be useful
40 for authors writing man pages for other projects.
41 .SS Sections of the Manual Pages
42 .PP
43 The manual Sections are traditionally defined as follows:
44 .RS
45 .TP 10
46 .B 1 Commands (Programs)
47 Those commands that can be executed by the user from within
48 a shell.
49 .TP
50 .B 2 System calls
51 Those functions which must be performed by the kernel.
52 .TP
53 .B 3 Library calls
54 Most of the
55 .I libc
56 functions.
57 .TP
58 .B 4 Special files (devices)
59 Files found in
60 .IR /dev .
61 .TP
62 .B 5 File formats and conventions
63 The format for
64 .I /etc/passwd
65 and other human-readable files.
66 .TP
67 .B 6 Games
68 .TP
69 .B 7 Conventions and miscellaneous
70 Overviews of various topics, conventions and protocols,
71 character set standards, and miscellaneous other things.
72 .TP
73 .B 8 System management commands
74 Commands like
75 .BR mount (8),
76 many of which only root can execute.
77 .\" .TP
78 .\" .B 9 Kernel routines
79 .\" This is an obsolete manual section.
80 .\" Once it was thought a good idea to document the Linux kernel here,
81 .\" but in fact very little has been documented, and the documentation
82 .\" that exists is outdated already.
83 .\" There are better sources of
84 .\" information for kernel developers.
85 .RE
86 .SS Macro package
87 New manual pages should be marked up using the
88 .B groff tmac.an
89 package described in
90 .BR man (7).
91 This choice is mainly for consistency: the vast majority of
92 existing Linux manual pages are marked up using these macros.
93 .SS Conventions for source file layout
94 Please limit source code line length to no more than about 75 characters
95 wherever possible.
96 This helps avoid line-wrapping in some mail clients when patches are
97 submitted inline.
98
99 New sentences should be started on new lines.
100 This makes it easier to see the effect of patches,
101 which often operate at the level of individual sentences.
102 .SS Title line
103 The first command in a man page should be a \fBTH\fP command:
104 .RS
105 .sp
106 .B \&.TH
107 .IR "title section date source manual"
108 .sp
109 .RE
110 where:
111 .RS
112 .TP 10
113 .I title
114 The title of the man page, written in all caps (e.g.,
115 .IR MAN-PAGES ).
116 .TP
117 .I section
118 The section number in which the man page should be placed (e.g.,
119 .IR 7 ).
120 .TP
121 .I date
122 The date of the last revision\(emremember to change this every time a
123 change is made to the man page,
124 since this is the most general way of doing version control.
125 Dates should be written in the form YYYY-MM-DD.
126 .TP
127 .I source
128 The source of the command, function, or system call.
129 .sp
130 For those few \fIman-pages\fP pages in Sections 1 and 8,
131 probably you just want to write
132 .IR GNU .
133 .sp
134 For system calls, just write
135 .IR "Linux" .
136 (An earlier practice was to write the version number
137 of the kernel from which the manual page was being written/checked.
138 However, this was never done consistently, and so was
139 probably worse than including no version number.
140 Henceforth, avoid including a version number.)
141 .sp
142 For library calls that are part of glibc or one of the
143 other common GNU libraries, just use
144 .IR "GNU C Library" ", " GNU ,
145 or an empty string.
146 .sp
147 For Section 4 pages, use
148 .IR "Linux" .
149 .sp
150 In cases of doubt, just write
151 .IR Linux ", or " GNU .
152 .TP
153 .I manual
154 The title of the manual (e.g., for Section 2 and 3 pages in
155 the \fIman-pages\fP package, use
156 .IR "Linux Programmer's Manual" ).
157 .RE
158 .SS Sections within a manual page
159 The list below shows conventional or suggested sections.
160 Most manual pages should include at least the
161 .B highlighted
162 sections.
163 Arrange a new manual page so that sections
164 are placed in the order shown in the list.
165 .in +0.5i
166 .nf
167
168 \fBNAME\fP
169 \fBSYNOPSIS\fP
170 \fBDESCRIPTION\fP
171 OPTIONS [Normally only in Sections 1, 8]
172 EXIT STATUS [Normally only in Sections 1, 8]
173 RETURN VALUE [Normally only in Sections 2, 3]
174 .\" May 07: Few current man pages have an ERROR HANDLING section,,,
175 .\" ERROR HANDLING,
176 ERRORS [Typically only in Sections 2, 3]
177 .\" May 07: Almost no current man pages have a USAGE section,,,
178 .\" USAGE,
179 ..\" DIAGNOSTICS,
180 .\" May 07: Almost no current man pages have a SECURITY section,,,
181 .\" SECURITY,
182 ENVIRONMENT
183 FILES
184 VERSIONS [Normally only in Sections 2, 3]
185 CONFORMING TO
186 NOTES
187 BUGS
188 EXAMPLE
189 .\" AUTHOR sections are discouraged
190 .\" AUTHOR [Discouraged]
191 \fBSEE ALSO\fP
192
193 .fi
194 .in
195 .IR "Where a traditional heading would apply" ", " "please use it" ;
196 this kind of consistency can make the information easier to understand.
197 If you must, you can create your own
198 headings if they make things easier to understand (this can
199 be especially useful for pages in Sections 4 and 5).
200 However, before doing this, consider whether you could use the
201 traditional headings, with some subsections (\fI.SS\fP) within
202 those sections.
203
204 The following list elaborates on the contents of each of
205 the above sections.
206 .TP 14
207 .B NAME
208 The name of this manual page.
209 See
210 .BR man (7)
211 for important details of the line(s) that should follow the
212 \fB.SH NAME\fI command.
213 .TP
214 .B SYNOPSIS
215 briefly describes the command or function's interface.
216 For commands, this shows the syntax of the command and its arguments
217 (including options);
218 boldface is used for as-is text and italics are used to
219 indicate replaceable arguments.
220 Brackets ([]) surround optional arguments, vertical bars (|)
221 separate choices, and ellipses (\&...) can be repeated.
222 For functions, it shows any required data declarations or
223 .B #include
224 directives, followed by the function declaration.
225 .TP
226 .B DESCRIPTION
227 gives an explanation of what the program, function, or format does.
228 Discuss how it interacts with files and standard input, and what it
229 produces on standard output or standard error.
230 Omit internals and implementation details unless they're critical for
231 understanding the interface.
232 Describe the usual case;
233 for information on command-line options of a program use the
234 .B OPTIONS
235 section.
236 .\" If there is some kind of input grammar or complex set of subcommands,
237 .\" consider describing them in a separate
238 .\" .B USAGE
239 .\" section (and just place an overview in the
240 .\" .B DESCRIPTION
241 .\" section).
242 .TP
243 .B OPTIONS
244 describes the command-line options accepted by a
245 program and how they change its behavior.
246 This section should only appear for Section 1 and 8 manual pages.
247 .\" .TP
248 .\" .B USAGE
249 .\" describes the grammar of any sublanguage this implements.
250 .TP
251 .B EXIT STATUS
252 lists the possible exit status values of a program and
253 the conditions that cause these values to be returned.
254 This section should only appear for Section 1 and 8 manual pages.
255 .TP
256 .B RETURN VALUE
257 For Section 2 and 3 pages, this section gives a
258 list of the values the library routine will return to the caller
259 and the conditions that cause these values to be returned.
260 .TP
261 .B ERRORS
262 For Section 2 and 3 manual pages, this is a list of the
263 values that may be placed in
264 .I errno
265 in the event of an error, along with information about the cause
266 of the errors.
267 .TP
268 .B ENVIRONMENT
269 lists all environment variables that affect the program or function
270 and how they affect it.
271 .TP
272 .B FILES
273 lists the files the program or function uses, such as
274 configuration files, startup files,
275 and files the program directly operates on.
276 Give the full pathname of these files, and use the installation
277 process to modify the directory part to match user preferences.
278 For many programs, the default installation location is in
279 .IR /usr/local ,
280 so your base manual page should use
281 .I /usr/local
282 as the base.
283 .\" May 07: Almost no current man pages have a DIAGNOSTICS section;
284 .\" "RETURN VALUE" or "EXIT STATUS" is preferred.
285 .\" .TP
286 .\" .B DIAGNOSTICS
287 .\" gives an overview of the most common error messages and how to
288 .\" cope with them.
289 .\" You don't need to explain system error messages
290 .\" or fatal signals that can appear during execution of any program
291 .\" unless they're special in some way to the program.
292 .\"
293 .\" May 07: Almost no current man pages have a SECURITY section.
294 .\".TP
295 .\".B SECURITY
296 .\"discusses security issues and implications.
297 .\"Warn about configurations or environments that should be avoided,
298 .\"commands that may have security implications, and so on, especially
299 .\"if they aren't obvious.
300 .\"Discussing security in a separate section isn't necessary;
301 .\"if it's easier to understand, place security information in the
302 .\"other sections (such as the
303 .\" .B DESCRIPTION
304 .\" or
305 .\" .B USAGE
306 .\" section).
307 .\" However, please include security information somewhere!
308 .TP
309 .B VERSIONS
310 A brief summary of the Linux kernel or glibc versions where a
311 system call or library function appeared,
312 or changed significantly in its operation.
313 .TP
314 .B CONFORMING TO
315 describes any standards or conventions that relate to the function
316 or command described by the manual page.
317 For a page in Section 2 or 3,
318 this section should note the POSIX.1
319 version(s) that the call conforms to,
320 and also whether the call is specified in C99.
321 (Don't worry too much about other standards like SUS, SUSv2, and XPG,
322 or the SVr4 and 4.xBSD implementation standards,
323 unless the call was specified in those standards,
324 but isn't in the current version of POSIX.1.)
325 (See
326 .BR standards (7).)
327
328 If the call is not governed by any standards but commonly
329 exists on other systems, note them.
330 If the call is Linux specific, note this.
331 .TP
332 .B NOTES
333 provides miscellaneous notes.
334 For Section 2 and 3 man pages you may find it useful to include
335 subsections (\fBSS\fP) named \fILinux Notes\fP and \fIGlibc Notes\fP.
336 .TP
337 .B BUGS
338 lists limitations, known defects or inconveniences,
339 and other questionable activities.
340 .TP
341 .B EXAMPLE
342 provides one or more examples describing how this function, file or
343 command is used.
344 For details on writing example programs,
345 see \fIExample Programs\fP below.
346 .TP
347 .B AUTHOR
348 lists authors of the documentation or program.
349 \fBUse of an AUTHOR section is discouraged\fP.
350 Generally, it is better not to clutter every page with a list
351 of (over time potentially numerous) authors;
352 if you write or significantly amend a page,
353 add a copyright notice as a comment in the source file.
354 If you are the author a device driver and what to include
355 an address for reporting bugs, place this under the BUGS section.
356 .TP
357 .B SEE ALSO
358 lists related man pages, ordered by section number and
359 alphabetically by name, possibly followed by
360 other related pages or documents.
361 .SS Font conventions
362 .PP
363 For functions, the arguments are always specified using italics,
364 .IR "even in the SYNOPSIS section" ,
365 where the rest of the function is specified in bold:
366 .PP
367 .RS
368 .BI " int myfunction(int " argc ", char **" argv );
369 .RE
370 .PP
371 Filenames are always in italics (e.g.,
372 .IR "/usr/include/stdio.h" ),
373 except in the SYNOPSIS section, where included files are in bold (e.g.,
374 .BR "#include <stdio.h>" ).
375 .PP
376 Special macros, which are usually in upper case, are in bold (e.g.,
377 .BR MAXINT ).
378 Exception: don't boldface NULL.
379 .PP
380 When enumerating a list of error codes, the codes are in bold (this list
381 usually uses the
382 .B \&.TP
383 macro).
384 .PP
385 Any reference to the subject of the current manual page
386 should be written with the name in bold.
387 If the subject is a function (i.e., this is a Section 2 or 3 page),
388 then the name should be followed by a pair of parentheses
389 in Roman (normal) font.
390 For example, in the
391 .BR fcntl (2)
392 man page, references to the subject of the page would be written as:
393 .BR fcntl ().
394 The preferred way to write this in the source file is:
395 .nf
396
397 .BR fcntl ()
398
399 .fi
400 (Using this format, rather than the use of "\\fB...\\fP()"
401 makes it easier to write tools that parse man page source files.)
402 .PP
403 Any reference to another man page
404 should be written with the name in bold,
405 \fIalways\fP followed by the section number,
406 formatted in Roman (normal) font, without any
407 separating spaces (e.g.,
408 .BR intro (2)).
409 The preferred way to write this in the source file is:
410 .nf
411
412 .BR intro (2)
413
414 .fi
415 (Including the section number in cross references lets tools like
416 .BR man2html (1)
417 create properly hyperlinked pages.)
418 .SS Example Programs
419 Manual pages can include example programs demonstrating how to
420 use a system call or library function.
421 However, note the following:
422 .TP 3
423 *
424 Example programs should be written in C.
425 .TP
426 *
427 An example program is only necessary and useful if it demonstrates
428 something beyond what can easily be provided in a textual
429 description of the interface.
430 An example program that does nothing
431 other than call an interface usually serves little purpose.
432 .TP
433 *
434 Example programs should be fairly short (preferably < 100 lines;
435 ideally < 50 lines).
436 .TP
437 *
438 Example programs should do error checking after system calls and
439 library function calls.
440 .TP
441 *
442 Example programs should be complete, and compile without
443 warnings when compiled with \fIcc -Wall\fP.
444 .TP
445 *
446 Where possible and appropriate, example programs should allow
447 experimentation, by varying their behaviour based on inputs
448 (ideally from command-line arguments, or alternatively, via
449 input read by the program).
450 .TP
451 *
452 Example programs should be laid out according to Kernighan and
453 Ritchie style, with a few concessions:
454 .RS
455 .TP 3
456 \(bu
457 4-space indents are preferred.
458 (Avoid the use of TAB characters in source code!)
459 .TP
460 \(bu
461 In the interests of keeping a program short, compressing
462 error-handling code such as in the following is acceptable:
463 .nf
464
465 if (func(...) == -1)
466 { perror("func"); exit(EXIT_FAILURE); }
467 .fi
468 .RE
469 .PP
470 For some examples of what example programs should look like, see
471 .BR wait (2)
472 and
473 .BR pipe (2).
474 .SH EXAMPLE
475 For canonical examples of how man pages in the
476 .IR man-pages
477 package should look, see
478 .BR pipe (2)
479 and
480 .BR fcntl (2).
481 .SH SEE ALSO
482 .BR man (1),
483 .BR man2html (1),
484 .BR man (7),
485 .BR mdoc (7)