9

Having used Linux for years, I suddenly found that I don't know how to use the man command properly. It is well known that one can type q to quit a man page, / to search, and others. I don't know, however, where are these documented. I tried man man man -a man info man and Googling, with no luck.

Please point me to the right position to look for this information, even if it is right in man man and I happen to have overlooked it, it's perfectly fine, just let me know.

Are these commands different for different OS or for different distributions of Linux?

6
  • Aren't man pages just viewed in less? (It is on my distribution, at least, and h shows a summary of less commands) Dec 7, 2017 at 11:45
  • @Rastapopoulos Aren't man pages just viewed in less? No. Because less isn't a standard utility. Dec 7, 2017 at 12:26
  • I suppose you can use readlink -f /usr/bin/pager or readlink -f $(which pager) to find out which pager you have (by default /bin/less) than man the used pager. It may (should) work directly man pager
    – Hastur
    Dec 7, 2017 at 13:25
  • 2
    If you read your man pages using more or less, you can type h for help. (or you can just use emacs...)
    – Alex Vong
    Dec 7, 2017 at 13:33
  • 1
    If you type ? or h at the pager prompt, it should give you a list of commands.
    – Barmar
    Dec 7, 2017 at 22:33

4 Answers 4

11

It is indeed right in the manual page for man, under the "Controlling formatted output" subheading and repeated later on in the "ENVIRONMENT" section for good measure:

By default, man uses pager -s.
The manual page explains how there is a hierarchy of environment variables and command-line options (PAGER, MANPAGER, and --pager) for overriding the default.

This is how it reads on systems such as Debian Linux. On systems such as Oracle Linux, in contrast, the man-db package has been built with a different default, which is however still reflected right there in the manual page in the same places:

By default, man uses less -s.

The man-db package attempts to auto-detect, at compile time, which default pager to build-in to the command, and document in its manual page, out of less, more, and pager.

On systems such as Debian Linux, the pager command is part of the "alternatives" system and can map to one of several actual commands:

jdebp % update-alternatives --list pager
/bin/less
/bin/more
/usr/bin/pg
/usr/bin/w3m
jdebp %

So one consults their respective manual pages for how to drive them from the keyboard, according to which alternative has been chosen. Usefully, the Debian alternatives system keeps the manual page in synch with the chosen command, so reading this manual page is quite straightforward:

man pager

0
5

Man uses a pager to show the content.

The exact details depend on which version of man you are using.

For the version used on many systems:

  • If the option -p pager is given then that pager is used.
  • Otherwise if the environment variable MANPAGER is set it is used.
  • Otherwise if PAGER is set it is used.
  • Otherwise the default is to use /usr/bin/less

If the manual page is in HTML format then BROWSER is used instead of MANPAGER/PAGER

Debian uses man-db which has different defaults.

Read man man for the details

3
  • Thank you for your answer. While the answer does explain how man works, I would like to ask you if you can do the favor to point me to the right place where this behavior is documented. Thank you. Dec 7, 2017 at 12:03
  • In my man man output (again, man version: 2.6.3) it states that "by default, less -s is used.", so I expect this is version- and system-dependent? Dec 7, 2017 at 12:05
  • 1
    This is just an example of the standard Unix philosophy: small and simple commands that operate on text streams and do exactly one thing and do it well. Formatting a manual, and paginating are two things which is why they are performed by two different tools. This way, the pagination tool can be re-used for other tasks, not only for displaying manual pages. Dec 7, 2017 at 23:18
2

Thanks to @Rastapopoulos, I find a line related to less in man man on a old Linux box (man version: 1.6f) in the ENVIRONMENT section that states,

BROWSER The name of a browser to use for displaying HTML manual pages. If it is not set, /usr/bin/less is used.

However on a newer box (man version: 2.6.3) this line has been replaced by

BROWSER If $BROWSER is set, its value is a colon-delimited list of commands, each of which in turn is used to try to start a web browser for man --html. In each command, %s is replaced by a file? name containing the HTML output from groff, %% is replaced by a single percent sign (%), and %c is replaced by a colon (:).

Based on these information I believe it is formatted in less by default (at least for the first case). However, even if this is the case, it is documented in a way that doesn't seem clear to me (or I have learnt the man command the wrong way).

2

There's no real way to fully answer your question in general for various operating systems, as the man implementation isn't really that fully specified.

The POSIX-standard, non-Linux-specific answer can be found in the POSIX man documentation:

NAME

man - display system documentation

SYNOPSIS

man [-k] name...

...

ENVIRONMENT VARIABLES

The following environment variables shall affect the execution of man:

LANG

Provide a default value for the internationalization variables that are unset or null. (See XBD Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and in the summary database). The value of LC_CTYPE need not affect the format of the information written about the name operands.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

PAGER

Determine an output filtering command for writing the output to a terminal. Any string acceptable as a command_string operand to the sh-c command shall be valid. When standard output is a terminal device, the reference page output shall be piped through the command. If the PAGER variable is null or not set, the command shall be either more or another paginator utility documented in the system documentation.

Note the RATIONALE section, describing why man isn't so fully specified:

RATIONALE

It is recognized that the man utility is only of minimal usefulness as specified. The opinion of the standard developers was strongly divided as to how much or how little information man should be required to provide. They considered, however, that the provision of some portable way of accessing documentation would aid user portability. The arguments against a fuller specification were:

  • Large quantities of documentation should not be required on a system that does not have excess disk space.

  • The current manual system does not present information in a manner that greatly aids user portability.

  • A "better help system" is currently an area in which vendors feel that they can add value to their POSIX implementations.

The -f option was considered, but due to implementation differences, it was not included in this volume of POSIX.1-2008.

The description was changed to be more specific about what has to be displayed for a utility. The standard developers considered it insufficient to allow a display of only the synopsis without giving a short description of what each option and operand does.

The "purpose" entry to be included in the database can be similar to the section title (less the numeric prefix) from this volume of POSIX.1-2008 for each utility. These titles are similar to those used in historical systems for this purpose.

See mailx for rationale concerning the default paginator.

The caveat in the LC_CTYPE description was added because it is not a requirement that an implementation provide reference pages for all of its supported locales on each system; changing LC_CTYPE does not necessarily translate the reference page into another language. This is equivalent to the current state of LC_MESSAGES in POSIX.1-2008-locale-specific messages are not yet a requirement.

The historical MANPATH variable is not included in POSIX because no attempt is made to specify naming conventions for reference page files, nor even to mandate that they are files at all. On some implementations they could be a true database, a hypertext file, or even fixed strings within the man executable. The standard developers considered the portability of reference pages to be outside their scope of work. However, users should be aware that MANPATH is implemented on a number of historical systems and that it can be used to tailor the search pattern for reference pages from the various categories (utilities, functions, file formats, and so on) when the system administrator reveals the location and conventions for reference pages on the system.

...

The paginator rationale discussion from the mailx page:

The paginator selected when PAGER is null or unset is partially unspecified to allow the System V historical practice of using pg as the default. Bypassing the pagination function, such as by declaring that cat is the paginator, would not meet with the intended meaning of this description. However, any "portable user" would have to set PAGER explicitly to get his or her preferred paginator on all systems. The paginator choice was made partially unspecified, unlike the VISUAL editor choice (mandated to be vi) because most historical pagers follow a common theme of user input, whereas editors differ dramatically.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .