2

I'm trying to understand how man works. Unfortunately man man doesn't yield answers for the following questions:

  1. Does the page for a command get installed with it or does man bring it from a remote database?
  2. If it brings it from the network, then how secure is it? Does it do it over TLS?
  3. Does man cache the pages locally? If it does, should I clear it on a regular basis?
J. Doe
  • 173
  • 1
  • 5
  • 1
    What OS's man are you using? POSIX explicitly doesn't state where man gets manpages from ("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.") – muru Mar 27 '20 at 03:09
  • Similar question: https://unix.stackexchange.com/a/90762/236063 – pLumo Mar 27 '20 at 07:49

2 Answers2

2

In modern unix-like systems following the Filesystem Hierarchy Standard, the man pages are normally stored in a directory tree located at /usr/share/man. Older unix-like systems might use /usr/man instead.

Usually man does not use network at all, although it's possible that someone somewhere has made a network-based implementation of it.

Commonly, the man pages are written using an old document formatting system originally known as roff (its GNU implementation is named groff). When viewing a man page, the man command will run the man page source code through the formatter, which will produce output tailored to the window width you're currently using. The formatter can also produce PostScript, PDF and possibly HTML renditions of man pages from the same source code, which won't be limited to terminal-style monospaced text.

The man command may cache the formatted text versions of man pages as cat pages for quicker re-viewing, typically in /var/cache/man (FHS) or separate sub-directories of the man page directory hierarchy (older systems). You may find that the system already includes a default (typically weekly) cron job that automatically cleans this cache for you.

If you have the CUPS printing system with the print-to-PDF feature enabled, run man -t ls | lp -d <name of your PDF virtual printer> and view the resulting output with any PDF viewer. Or man -Thtml ls > ls_man_page.html to get a HTML version. (This is for Debian 10's man-db implementation of the man command: the formatting options may be different in other implementations.)

telcoM
  • 96,466
1

Does the page for a command get installed with it

Yes, it usually does but of course you can always add a new custom manpage to your system without using your local package management system. You can use your system package manager to learn what package a given manpage com from. A big portion of manpages on Linux-based systems comes from the Linux man-pages project.

If it brings it from the network, then how secure is it?

It doesn't but as others said it's possible that someone has written their own implementation that does. I guess that your confusion might come from the first line in man man that says:

man - an interface to the on-line reference manuals

Or in BSD version:

man — display online manual documentation pages

See this LQ question for an explanation.

For fun see also https://explainshell.com. It's a nice site that can quickly explain meaning of options in a given command, for example https://explainshell.com/explain?cmd=ls+-Alhtr but remember that your local implementation of a given command may differ or may not support all options (this is especially true when using small Busybox-like based systems).

And of course man can work via network in a sense that you can mount a remote directory locally and tell man to look for manpages there, for example I can read manpages from the remote FreeBSD machine like that:

$ sshfs freebsd:/usr/share/man /mnt/bsd-manpages
$ MANPATH=/mnt/bsd-manpages man man
$ MAN(1)                                                                                

    BSD General Commands Manual                                                                                   MAN(1)

NAME
     man — display online manual documentation pages

Does man cache the pages locally? If it does, should I clear it on a regular basis?

Already well explained in telcoM's answer.