Revision as of 22:01, 30 July 2013

man pages (abbreviation for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial UNIX-like operating systems, including Arch Linux. The command used to display them is man.

In spite of their scope, man pages are designed to be self-contained documents, consequentially limiting themselves to referring to other man pages when discussing related subjects. This is in sharp contrast with the hyperlink-aware info files, GNU's attempt at replacing the traditional man page format.

Man pages are usually referred to by their name, followed by their section number in parentheses. Often there are multiple man pages of the same name, such as man(1) and man(7). In this case, give man the section number followed by the name of the man page, for example:

$ man 5 passwd

to read the man page on /etc/passwd, rather than the passwd utility.

Very brief descriptions of programs can be read out of man pages without displaying the whole page using the whatis command. For example, for a brief description of ls, type:

$ whatis ls

and whatis will output "list directory contents."

Format

Man pages all follow a fairly standard format, which helps in navigating them. Some sections which are often present include:

NAME - The name of the command and a one-line statement of its purpose.

SYNOPSIS - A list of the options and arguments a command takes or the parameters the function takes and its header file.

DESCRIPTION - A more in depth description of a command or function's purpose and workings.

EXAMPLES - Common examples, usually ranging from the simple to the relatively complex.

OPTIONS - Descriptions of each of the options a command takes and what they do.

EXIT STATUS - The meanings of different exit codes.

FILES - Files related to a command or function.

BUGS - Problems with the command or function that are pending repair. Also known as KNOWN BUGS.

SEE ALSO - A list of related commands or functions.

AUTHOR, HISTORY, COPYRIGHT, LICENSE, WARRANTY - Information about the program, its past, its terms of use, and its creator.

Searching manuals

Whilst the man utility allows users to display man pages, a problem arises when one knows not the exact name of the desired manual page in the first place! Fortunately, the -k or --apropos options can be used to search the manual page descriptions for instances of a given keyword.

The research feature is provided by a dedicated cache. By default you may not have any cache built and all your searches will give you the nothing appropriate result. You can generate the cache or update it by running

# mandb

You should run it everytime a new manpage is installed.

Now you can begin your search.
For example, to search for man pages related to "password":

$ man -k password

or:

$ man --apropos password

This is equivalent to calling the apropos command:

$ apropos password

The given keyword is interpreted as a regular expression by default.

If you want to do a more in-depth search by matching the keywords found in the whole articles, you can use the -K option:

$ man -K password

Colored man pages

Color-enabled man pages allow for a clearer presentation and easier digestion of the content.
There are two prevalent methods for achieving colored man pages: using less, or opting for most.

Using most (Not recommended)

The basic function of 'most' is similar to less and more, but it has a smaller feature set. Configuring most to use colors is easier than using less, but additional configuration is necessary to make most behave like less.
Install most using pacman:

# pacman -S most

Edit /etc/man_db.conf, uncomment the pager definition and change it to:

DEFINE pager most -s

Test the new setup by typing:

$ man whatever_man_page

Modifying the color values requires editing ~/.mostrc (creating the file if it is not present) or editing /etc/most.conf for system-wide changes. Example ~/.mostrc:

xterm

if you want colors and decorations (bold or underline) at the same time. See man xterm for a description of the veryBoldColors resource.

rxvt-unicode

URxvt.colorIT: #87af5f
URxvt.colorBD: #d7d7d7
URxvt.colorUL: #87afd7

Run:

$ xrdb -load ~/.Xresources

Launch a new xterm/uxterm or rxvt-unicode and you should see colorful man pages.
This combination puts colors to bold and underlined words in xterm/uxterm or to bold, underlined, and italicized text in rxvt-unicode. You can play with different combinations of these attributes (see the sources of this item).

Reading local man pages

Instead of the standard interface, using browsers such as lynx and Firefox to view man pages allows users to reap info pages' main benefit: hyperlinked text.

The GNU implementation of man in the Arch repositories also has the ability to do this on its own:

$ man -H free

This will read your BROWSER environment variable to determine the browser. You can override this by passing the binary to the -H option.

Converting to PDF

man pages have always been printable: they are written in troff, which is fundamentally a typesetting language. If you have ghostscript installed, converting a man page to PDF is actually very easy: man -t <manpage> | ps2pdf - <pdf>. This google image search should give you an idea of what the result looks like; it may not be to everybody's liking.

Caveats: Fonts are generally limited to Times at hardcoded sizes. There are no hyperlinks. Some man pages were specifically designed for terminal viewing, and won't look right in PS or PDF form.

The following perl script converts man pages to PDFs, caches the PDFs in the $HOME/.manpdf/ directory, and calls a PDF viewer, specifically mupdf.