1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
The FreeBSD Documentation Project
-->
<chapter xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
xml:id="manpages">
<title>Manual Pages</title>
<sect1 xml:id="manpages-introduction">
<title>Introduction</title>
<para><emphasis>Manual pages</emphasis>, commonly shortened to
<emphasis>man pages</emphasis>, were conceived as
readily-available reminders for command syntax, device driver
details, or configuration file formats. They have become an
extremely valuable quick-reference from the command line for
users, system administrators, and programmers.</para>
<para>Although intended as reference material rather than
tutorials, the EXAMPLES sections of manual pages often
provide detailed use case.</para>
<para>Manual pages are generally shown interactively by the
&man.man.1; command. When the user types
<command>man ls</command>, a search is performed for a manual
page matching <literal>ls</literal>. The first matching result
is displayed.</para>
</sect1>
<sect1 xml:id="manpages-sections">
<title>Sections</title>
<para>Manual pages are grouped into <emphasis>sections</emphasis>.
Each section contains manual pages for a specific category of
documentation:</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Section Number</entry>
<entry>Category</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>General Commands</entry>
</row>
<row>
<entry>2</entry>
<entry>System Calls</entry>
</row>
<row>
<entry>3</entry>
<entry>Library Functions</entry>
</row>
<row>
<entry>4</entry>
<entry>Kernel Interfaces</entry>
</row>
<row>
<entry>5</entry>
<entry>File Formats</entry>
</row>
<row>
<entry>6</entry>
<entry>Games</entry>
</row>
<row>
<entry>7</entry>
<entry>Miscellaneous</entry>
</row>
<row>
<entry>8</entry>
<entry>System Manager</entry>
</row>
<row>
<entry>9</entry>
<entry>Kernel Developer</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1>
<sect1 xml:id="manpages-markup">
<title>Markup</title>
<para>Various markup forms and rendering programs have been used
for manual pages. &os; has used &man.groff.7; and the newer
&man.mandoc.1;. Most existing &os; manual pages, and all new
ones, use the &man.mdoc.7; form of markup. This is a simple
line-based markup that is reasonably expressive. It is mostly
semantic: parts of text are marked up for what they are, rather
than for how they should appear when rendered. There is some
appearance-based markup which is usually best avoided.</para>
<para>Manual page source is usually interpreted and displayed to
the screen interactively. The source files can be ordinary text
files or compressed with &man.gzip.1; to save space.</para>
<para>Manual pages can also be rendered to other formats,
including PostScript for printing or <acronym>PDF</acronym>
generation. See &man.man.1;.</para>
<sect2 xml:id="manpages-markup-sections">
<title>Manual Page Sections</title>
<para>Manual pages are composed of several standard sections.
Each section has a title in upper case, and the sections for a
particular type of manual page appear in a specific order.
For a category 1 General Command manual page, the sections
are:</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Section Name</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>NAME</entry>
<entry>Name of the command</entry>
</row>
<row>
<entry>SYNOPSIS</entry>
<entry>Format of options and arguments</entry>
</row>
<row>
<entry>DESCRIPTION</entry>
<entry>Description of purpose and usage</entry>
</row>
<row>
<entry>ENVIRONMENT</entry>
<entry>Environment settings that affect
operation</entry>
</row>
<row>
<entry>EXIT STATUS</entry>
<entry>Error codes returned on exit</entry>
</row>
<row>
<entry>EXAMPLES</entry>
<entry>Examples of usage</entry>
</row>
<row>
<entry>COMPATIBILITY</entry>
<entry>Compatibility with other implementations</entry>
</row>
<row>
<entry>SEE ALSO</entry>
<entry>Cross-reference to related manual pages</entry>
</row>
<row>
<entry>STANDARDS</entry>
<entry>Compatibility with standards like POSIX</entry>
</row>
<row>
<entry>HISTORY</entry>
<entry>History of implementation</entry>
</row>
<row>
<entry>BUGS</entry>
<entry>Known bugs</entry>
</row>
<row>
<entry>AUTHORS</entry>
<entry>People who created the command or wrote the
manual page.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>Some sections are optional, and the combination of
sections for a specific type of manual page vary. Examples of
the most common types are shown later in this chapter.</para>
</sect2>
<sect2 xml:id="manpages-markup-macros">
<title>Macros</title>
<para>&man.mdoc.7; markup is based on
<emphasis>macros</emphasis>. Lines that begin with a dot
contain macro commands, each two or three letters long. For
example, consider this portion of the &man.ls.1; manual
page:</para>
<programlisting xml:id="manpages-markup-macros-example-ls">
.Dd December 1, 2015 <co xml:id="co-manpages-macro-example-ls-1"/>
.Dt LS 1
.Sh NAME <co xml:id="co-manpages-macro-example-ls-2"/>
.Nm ls
.Nd list directory contents
.Sh SYNOPSIS <co xml:id="co-manpages-macro-example-ls-3"/>
.Nm <co xml:id="co-manpages-macro-example-ls-4"/>
.Op Fl -libxo <co xml:id="co-manpages-macro-example-ls-5"/>
.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1, <co xml:id="co-manpages-macro-example-ls-6"/>
.Op Fl D Ar format <co xml:id="co-manpages-macro-example-ls-7"/>
.Op Ar <co xml:id="co-manpages-macro-example-ls-8"/>
.Sh DESCRIPTION <co xml:id="co-manpages-macro-example-ls-9"/>
For each operand that names a
.Ar file
of a type other than
directory,
.Nm
displays its name as well as any requested,
associated information.
For each operand that names a
.Ar file
of type directory,
.Nm
displays the names of files contained
within that directory, as well as any requested, associated
information.</programlisting>
<calloutlist>
<callout arearefs="co-manpages-macro-example-ls-1">
<para>A <emphasis>Document date</emphasis> and
<emphasis>Document title</emphasis> are defined.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-2">
<para>A <emphasis>Section header</emphasis> for the NAME
section is defined. Then the <emphasis>Name</emphasis>
of the command and a one-line
<emphasis>Name description</emphasis> are defined.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-3">
<para>The SYNOPSIS section begins. This section describes
the command-line options and arguments accepted.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-4">
<para><emphasis>Name</emphasis> (<literal>.Nm</literal>) has
already been defined, and repeating it here just displays
the defined value in the text.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-5">
<para>An <emphasis>Optional</emphasis>
<emphasis>Flag</emphasis> called <literal>-libxo</literal>
is shown. The <literal>Fl</literal> macro adds a dash to
the beginning of flags, so this appears in the manual
page as <literal>--libxo</literal>.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-6">
<para>A long list of optional single-character flags are
shown.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-7">
<para>An optional <literal>-D</literal> flag is defined. If
the <literal>-D</literal> flag is given, it must be
followed by an <emphasis>Argument</emphasis>. The
argument is a <emphasis>format</emphasis>, a string that
tells &man.ls.1; what to display and how to display it.
Details on the format string are given later in the manual
page.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-8">
<para>A final optional argument is defined. Because no name
is specified for the argument, the default of
<literal>file ...</literal> is used.</para>
</callout>
<callout arearefs="co-manpages-macro-example-ls-9">
<para>The <emphasis>Section header</emphasis> for the
DESCRIPTION section is defined.</para>
</callout>
</calloutlist>
<para>When rendered with the command <command>man ls</command>,
the result displayed on the screen looks like this:</para>
<programlisting>LS(1) FreeBSD General Commands Manual LS(1)
NAME
ls — list directory contents
SYNOPSIS
ls [--libxo] [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format]
[file ...]
DESCRIPTION
For each operand that names a file of a type other than directory, ls
displays its name as well as any requested, associated information. For
each operand that names a file of type directory, ls displays the names
of files contained within that directory, as well as any requested,
associated information.</programlisting>
<para>Optional values are shown inside square brackets.</para>
</sect2>
<sect2 xml:id="manpages-markup-guidelines">
<title>Markup Guidelines</title>
<para>The &man.mdoc.7; markup language is not very strict. For
clarity and consistency, the &os; Documentation project adds
some additional style guidelines:</para>
<variablelist>
<varlistentry>
<term>Only the first letter of macros is upper case</term>
<listitem>
<para>Always use upper case for the first letter of a
macro and lower case for the remaining letters.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Begin new sentences on new lines</term>
<listitem>
<para>Start a new sentence on a new line, do not begin it
on the same line as an existing sentence.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Update <literal>.Dd</literal> when making non-trivial
changes to a manual page</term>
<listitem>
<para>The <emphasis>Document date</emphasis> informs the
reader about the last time the manual page was updated.
It is important to update whenever non-trivial changes
are made to the manual pages. Trivial changes like
spelling or punctuation fixes that do not affect usage
can be made without updating
<literal>.Dd</literal>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Give examples</term>
<listitem>
<para>Show the reader examples when possible. Even
trivial examples are valuable, because what is trivial
to the writer is not necessarily trivial to the reader.
Three examples are a good goal. A trivial example shows
the minimal requirements, a serious example shows actual
use, and an in-depth example demonstrates unusual or
non-obvious functionality.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Include the BSD license</term>
<listitem>
<para>Include the BSD license on new manual pages. The
preferred license is available from the <link
xlink:href="&url.articles.committers-guide;pref-license">Committer's
Guide</link>.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 xml:id="manpages-markup-tricks">
<title>Markup Tricks</title>
<para>Add a space before punctuation on a line with
macros. Example:</para>
<programlisting>.Sh SEE ALSO
.Xr geom 4 ,
.Xr boot0cfg 8 ,
.Xr geom 8 ,
.Xr gptboot 8</programlisting>
<para>Note how the commas at the end of the
<literal>.Xr</literal> lines have been placed after a space.
The <literal>.Xr</literal> macro expects two parameters to
follow it, the name of an external manual page, and a section
number. The space separates the punctuation from the section
number. Without the space, the external links would
incorrectly point to section <literal>4,</literal> or
<literal>8,</literal>.</para>
</sect2>
<sect2 xml:id="manpages-markup-important-macros">
<title>Important Macros</title>
<para>Some very common macros will be shown here. For
more usage examples, see &man.mdoc.7;, &man.groff.mdoc.7;, or
search for actual use in
<filename>/usr/share/man/man*</filename> directories. For
example, to search for examples of the <literal>.Bd</literal>
<emphasis>Begin display</emphasis> macro:</para>
<screen>&prompt.user; <userinput>find /usr/share/man/man* | xargs zgrep '.Bd'</userinput></screen>
<sect3 xml:id="manpages-markup-important-macros-organizational">
<title>Organizational Macros</title>
<para>Some macros are used to define logical blocks of a
manual page.</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Organizational Macro</entry>
<entry>Use</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>.Sh</literal></entry>
<entry>Section header. Followed by the name of
the section, traditionally all upper case.
Think of these as chapter titles.</entry>
</row>
<row>
<entry><literal>.Ss</literal></entry>
<entry>Subsection header. Followed by the name of
the subsection. Used to divide a
<literal>.Sh</literal> section into
subsections.</entry>
</row>
<row>
<entry><literal>.Bl</literal></entry>
<entry>Begin list. Start a list of items.</entry>
</row>
<row>
<entry><literal>.El</literal></entry>
<entry>End a list.</entry>
</row>
<row>
<entry><literal>.Bd</literal></entry>
<entry>Begin display. Begin a special area of
text, like an indented area.</entry>
</row>
<row>
<entry><literal>.Ed</literal></entry>
<entry>End display.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect3>
<sect3 xml:id="manpages-markup-important-macros-inline">
<title>Inline Macros</title>
<para>Many macros are used to mark up inline text.</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Inline Macro</entry>
<entry>Use</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>.Nm</literal></entry>
<entry>Name. Called with a name as a parameter on the
first use, then used later without the parameter to
display the name that has already been
defined.</entry>
</row>
<row>
<entry><literal>.Pa</literal></entry>
<entry>Path to a file. Used to mark up filenames and
directory paths.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect3>
</sect2>
</sect1>
<sect1 xml:id="manpages-sample-structures">
<title>Sample Manual Page Structures</title>
<para>This section shows minimal desired man page contents for
several common categories of manual pages.</para>
<sect2 xml:id="manpages-sample-structures-section-1-8">
<title>Section 1 or 8 Command</title>
<para>The preferred basic structure for a section 1 or 8
command:</para>
<programlisting xml:id="manpages-sample-structures-section-1-8-sample">.Dd August 25, 2017
.Dt EXAMPLECMD 8
.Os
.Sh NAME
.Nm examplecmd
.Nd "command to demonstrate section 1 and 8 man pages"
.Sh SYNOPSIS
.Nm
.Op Fl v
.Sh DESCRIPTION
The
.Nm
utility does nothing except demonstrate a trivial but complete
manual page for a section 1 or 8 command.
.Sh SEE ALSO
.Xr exampleconf 5
.Sh AUTHORS
.An Firstname Lastname Aq Mt flastname@example.com</programlisting>
</sect2>
<sect2 xml:id="manpages-sample-structures-section-4">
<title>Section 4 Device Driver</title>
<para>The preferred basic structure for a section 4 device
driver:</para>
<programlisting xml:id="manpages-sample-structures-section-4-sample">.Dd August 25, 2017
.Dt EXAMPLEDRIVER 4
.Os
.Sh NAME
.Nm exampledriver
.Nd "driver to demonstrate section 4 man pages"
.Sh SYNOPSIS
To compile this driver into the kernel, add this line to the
kernel configuration file:
.Bd -ragged -offset indent
.Cd "device exampledriver"
.Ed
.Pp
To load the driver as a module at boot, add this line to
.Xr loader.conf 5 :
.Bd -literal -offset indent
exampledriver_load="YES"
.Ed
.Sh DESCRIPTION
The
.Nm
driver provides an opportunity to show a skeleton or template
file for section 4 manual pages.
.Sh HARDWARE
The
.Nm
driver supports these cards from the aptly-named Nonexistent
Technologies:
.Pp
.Bl -bullet -compact
.It
NT X149.2 (single and dual port)
.It
NT X149.8 (single port)
.El
.Sh DIAGNOSTICS
.Bl -diag
.It "flashing green light"
Something bad happened.
.It "flashing red light"
Something really bad happened.
.It "solid black light"
Power cord is unplugged.
.El
.Sh SEE ALSO
.Xr example 8
.Sh HISTORY
The
.Nm
device driver first appeared in
.Fx 49.2 .
.Sh AUTHORS
.An Firstname Lastname Aq Mt flastname@example.com</programlisting>
</sect2>
<sect2 xml:id="manpages-sample-structures-section-5">
<title>Section 5 Configuration File</title>
<para>The preferred basic structure for a section 5
configuration file:</para>
<programlisting xml:id="manpages-sample-structures-section-5-sample">.Dd August 25, 2017
.Dt EXAMPLECONF 5
.Os
.Sh NAME
.Nm example.conf
.Nd "config file to demonstrate section 5 man pages"
.Sh DESCRIPTION
.Nm
is an example configuration file.
.Sh SEE ALSO
.Xr example 8
.Sh AUTHORS
.An Firstname Lastname Aq Mt flastname@example.com</programlisting>
</sect2>
</sect1>
<sect1 xml:id="manpages-testing">
<title>Testing</title>
<para>Testing a new manual page can be challenging. Fortunately
there are some tools that can assist in the task. Some of them,
like &man.man.1;, do not look in the current directory. It is a
good idea to prefix the filename with <literal>./</literal> if
the new manual page is in the current directory. An absolute
path can also be used.</para>
<para>Use &man.mandoc.1;'s linter to check for parsing
errors:</para>
<screen>&prompt.user; <userinput>mandoc -T lint ./mynewmanpage.8</userinput></screen>
<para>Use <package>textproc/igor</package> to proofread the
manual page:</para>
<screen>&prompt.user; <userinput>igor ./mynewmanpage.8</userinput></screen>
<para>Use &man.man.1; to check the final result of your
changes:</para>
<screen>&prompt.user; <userinput>man ./mynewmanpage.8</userinput></screen>
<para>You can use &man.col.1; to filter the output of
&man.man.1; and get rid of the backspace characters before
loading the result in your favorite editor for
spell checking:</para>
<screen>&prompt.user; <userinput>man ./mynewmanpage.8 | col -b | vim -R -</userinput></screen>
<para>Spell-checking with fully-featured dictionaries is
encouraged, and can be accomplished by using
<package>textproc/hunspell</package> or
<package>textproc/aspell</package> combined with
<package>textproc/en-hunspell</package> or
<package>textproc/en-aspell</package>, respectively.
For instance:</para>
<screen>&prompt.user; <userinput>aspell check --lang=en --mode=nroff ./mynewmanpage.8</userinput></screen>
</sect1>
<sect1 xml:id="manpages-examples-as-templates">
<title>Example Manual Pages to Use as Templates</title>
<para>Some manual pages are suitable as in-depth examples.</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Manual Page</entry>
<entry>Path to Source Location</entry>
</row>
</thead>
<tbody>
<row>
<entry>&man.cp.1;</entry>
<entry><filename>/usr/src/bin/cp/cp.1</filename></entry>
</row>
<row>
<entry>&man.vt.4;</entry>
<entry><filename>/usr/src/share/man/man4/vt.4</filename></entry>
</row>
<row>
<entry>&man.crontab.5;</entry>
<entry><filename>/usr/src/usr.sbin/cron/crontab/crontab.5</filename></entry>
</row>
<row>
<entry>&man.gpart.8;</entry>
<entry><filename>/usr/src/sbin/geom/class/part/gpart.8</filename></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect1>
<sect1 xml:id="manpages-resources">
<title>Resources</title>
<para>Resources for manual page writers:</para>
<itemizedlist>
<listitem>
<para>&man.man.1;</para>
</listitem>
<listitem>
<para>&man.mandoc.1;</para>
</listitem>
<listitem>
<para>&man.groff.mdoc.7;</para>
</listitem>
<listitem>
<para><link
xlink:href="http://manpages.bsd.lv/mdoc.html">Practical
UNIX Manuals: mdoc</link></para>
</listitem>
<listitem>
<para><link
xlink:href="http://manpages.bsd.lv/history.html">History
of UNIX Manpages</link></para>
</listitem>
</itemizedlist>
</sect1>
</chapter>
|