2
头图
Summary :
I will sort out the various usages of man, which can also be used as a reference manual by the way.
<!--MORE-->

Introduction

man is a Linux command line utility that displays help manuals for linux commands, system calls, library functions, etc.

man page , namely Manual pages, also known as man page, in Unix or class Unix operating system online software documentation one common form. The content includes computer program (including library and system call ), formal standards and conventions, and even abstract concepts. user can call the manual page by executing man command

The man page is designed as an independent document, and other manual pages cannot be referenced. This is in Info document that supports hyperlinks. GNU is replacing the man manual with the info document.

The default format of the man page is troff , using man macro package (emphasis on presentation) or mdoc macro package (emphasis on semantics). You can typeset the manual pages into PostScript , PDF and various other formats for viewing or printing.

Install

man-db provides man command, less is the default pager man

image-20211226010348217

man-pages provides the contents of Linux man pages.

image-20211226010416504

Here are the translated versions in some languages:

The following program can also be used to read the manual:

  • GNOME Help GNOME Help reader program. Use the yelp man:<name> or Ctrl+L shortcut keys to read the manual page.
  • KHelpCenter KDE helps to read the program, you can read the manual khelpcenter man:<name>
  • Konqueror — KDE files and web browsers, manuals man:<name>
  • xman — You can view the manual by category.

For Linux distributions, man is the standard configuration, and any minimal system includes the man command (that is, the man-db package is always pre-installed), but the document content of the man page is not necessarily Optional.

For systems like Ubuntu, application manual pages often -doc . For example, the supporting manual page of the flex package is the flex-doc package.

sudo apt install flex flex-doc
sudo apt install bison bison-doc
sudo apt install git git-doc

For those who are more concerned about POSIX portability, you may need to install:

sudo apt install manpages-poxis*

Then you can look up POSIX calls, for example:

man 3p connect

etc.

Read the man page

Read the man page with the following command:

$ man 手册名

The man page is divided into many sections. For a complete list, please refer to: man-pages(7) .

The man page is identified by its name and category. Some man pages of different categories may have the same name, such as man(1) and man(7). In this case, you need to specify the category to access the required manual. For example:

$ man 5 passwd

The content of the /etc/passwd will be displayed instead of the command passwd

Shortcut key ( less )

In the manual page reading interface, you can use shortcut keys to help reading.

Since the display of the manual page is done using the default PAGER in the operating system Shell environment, the shortcut keys follow the function mapping of the corresponding PAGER.

Most systems now default to less as the default PAGER, so please refer to less command omniscience plenary .

layout

All manual pages follow a common layout, which is ASCII text display, and in this case there may not be any form of highlighting or font control. Generally include the following parts:

  • NAME

    The name of the command or function, followed by a line of introduction.

  • SYNOPSIS (Summary)

    For the command ), formally describe how it runs and what command-line parameters are required. For functions, introduce the parameters required by the function and which header file contains the definition of the function.

  • DESCRIPTION

    Text description of the function of the command or function.

  • EXAMPLES

    Some commonly used examples.

  • SEE ALSO (see)

    List of related commands or functions.

There may be other parts, but these parts are not standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY And COPYRIGHT (copyright).

You can the descriptions of the blocks in these man pages man-pages(7)

A more complete list is excerpted as follows:

NAME
SYNOPSIS
CONFIGURATION[Normally only in Section 4]
DESCRIPTION
OPTIONS[Normally only in Sections 1, 8]
EXIT STATUS[Normally only in Sections 1, 8]
RETURN VALUE[Normally only in Sections 2, 3]
ERRORS[Typically only in Sections 2, 3]
ENVIRONMENT
FILES
VERSIONS[Normally only in Sections 2, 3]
ATTRIBUTES[Normally only in Sections 2, 3]
CONFORMING TO
NOTES
BUGS
EXAMPLES
AUTHORS[Discouraged]
REPORTING BUGS[Not used in man-pages]
COPYRIGHT[Not used in man-pages]
SEE ALSO

Manual block

In the operating system, all manual pages are divided into multiple sections according to their subject classification, such as system calls, Shell commands, C library functions, and so on. These blocks are mainly located in the /usr/share/man/man1 to /usr/share/man/man9 .

In Arch Linux, Research Unix , BSD , OS X and Linux , the manual is usually divided into 8 blocks, arranged as follows:

Blockinstruction
1General command )
2 system call
3 library function, covering C standard function library
4 special file (usually a device in /dev) and driver
5 file format and conventions
6 game and screensaver
7Miscellaneous
8System management command ) and daemon

Unix System V uses a similar numbering scheme, but in a different order:

Blockinstruction
1General command )
1MSystem management command ) and daemon
2 system call
3 C function library function
4 file format and conventions
5Miscellaneous
6 game and screensaver
7 special file (usually a device in /dev) and driver

In some systems, the following blocks are also available:

Blockdescribe
0 C function library header file
9 kernel
n Tcl / Tk Keyword
x X Window System

Some blocks are further subdivided using suffixes. For example, in some systems, block 3C is the C function library call, 3M is the math (Math) function library, and so on. The result of this is that block 8 (system management commands) is sometimes moved to block 1M (as a sub-block of the command Some sub-block suffixes have general meanings across blocks:

Sub-blockinstruction
p POSIX specification
x X Window System Document
pmPerl Module function

Summary

In summary, the main categories and corresponding numbers of man pages are:

0     Header files
0p    Header files (POSIX)
1     Executable programs or shell commands
1p    Executable programs or shell commands (POSIX)
2     System calls (functions provided by the kernel)
3     Library calls (functions within program libraries)
3n    Network Functions
3p,3pm    Perl Modules
4     Special files (usually found in /dev)
5     File formats and conventions eg /etc/passwd
6     Games
7     Miscellaneous  (including  macro  packages and conventions), e.g. man(7), groff(7)
8     System administration commands (usually only for root)
9     Kernel routines
l     Local documentation
n     New manpages

Roughly translated:

  • 0, 0p: Obsolete, the corresponding entry has been merged into section 3.
  • l, n: Basically not in the release, but developers can use it in the development cycle.
  • 1: Executable program or shell command.
  • 2: System calls (system calls, functions provided by the Linux kernel).
  • 3: General library functions, C library functions.
  • 4: Special files (usually located in /dev ).
  • 5: The file format is in agreement, such as /etc/passwd
  • 6: Games.
  • 7: Miscellaneous (macro processing, etc., such as man(7) , groff(7) ).
  • 8: System administrator instruction (usually a special instruction root
  • 9: Kernel routines (non-standard).

Note that as mentioned above, in most systems, there are only blocks 1 to 8. You can man-pages(7) , as we described above.

In the manual page system, parentheses are used to indicate the block to which the manual belongs. For example, ls(1) indicates that the Shell command ls belongs to block 1.

Sometimes a topic name may have different description files in different blocks. If a topic cannot be found in the specified block when searching for a topic, then man will search the corresponding other blocks in sequence in the order of 1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7 The content of the first searched chapter.

For example passwd this theme passwd(1) and passwd(5) two chapters, if not specified chapter words:

man passwd

passwd(1) will be displayed, and if you want to query passwd(5) , you should clearly specify the block number:

man 5 passwd

If you are confused about this syntax, you can use the following format:

man passwd.5

The two are equivalent.

List all chapters

Due to the complexity of the specific topic, some entries may not be in the partition you think. For example, the reference of the recv C function is not in partition 3, but in partition 2, because it is one of the Linux kernel calls. This situation is often seen when the system call and the C library function have the same name.

Sometimes we are very interested in a topic, but do not know which chapters of the topic can be queried, then we can use the -aw parameter to query:

man -aw printf

A typical result might look like this:

/usr/share/man/man1/printf.1.gz
/usr/share/man/man1/printf.1posix.gz
/usr/share/man/man3/printf.3.gz
/usr/share/man/man3/printf.3posix.gz

But you might prefer the results returned by whatis:

$ whatis printf
printf (1)           - format and print data
printf (3)           - formatted output conversion
printf (1posix)      - write formatted output
printf (3posix)      - print formatted output

It is more intuitive.

whatis is equivalent to man -f :

$ man -f printf
printf (1)           - format and print data
printf (3)           - formatted output conversion
printf (1posix)      - write formatted output
printf (3posix)      - print formatted output

View all chapters at once

If you want to view all chapters of a topic at once, you can use the -a , which will make man display all chapters in turn:

man -a printf

When you finish reading a chapter and press q exit, man will display:

--Man-- next: printf(3) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

j Simply press Enter (press Enter) to continue reading the next chapter. You can also use Ctrl-C to terminate man and return to the Shell prompt state.

Search man pages

What if the user does not know the name of the manual to be consulted? It's okay, you can search for related manuals by given keywords -k or --apropos For example, to consult the manual about passwords ("password"):

$ man -k password
chage (1)            - change user password expiry information
chgpasswd (8)        - update group passwords in batch mode
chpasswd (8)         - update passwords in batch mode
...
pam_unix (8)         - Module for traditional password authentication
passwd (1)           - change user password
passwd (1ssl)        - compute password hashes
passwd (5)           - the password file
passwd2des (3)       - RFS password encryption
...
pwd.h (7posix)       - password structure
...
shadow (5)           - shadowed password file
shadowconfig (8)     - toggle shadow passwords on and off
smbpasswd (5)        - The Samba encrypted password file
smbpasswd (8)        - change a user's SMB password
...
xdecrypt (3)         - RFS password encryption
xencrypt (3)         - RFS password encryption

man -k will filter the topic name and short description text to try to match the given keywords.

Now you can start searching. For example, to consult the manual about passwords ("password"), you can use the following command:

$ man -k password
$ man --apropos password
$ apropos password

They are synonyms.

Keywords can use regular expressions.

For example

$ man -k sprintf
asprintf (3)         - print to allocated string
sprintf (3)          - formatted output conversion
Text::sprintfn (3pm) - Drop-in replacement for sprintf(), with named parameter support
vasprintf (3)        - print to allocated string
vsprintf (3)         - formatted output conversion

Note that to get the above results, you need to install it first:

sudo apt install libtext-sprintfn-perl

To ensure that the Text::sprintfn (3pm) entry already exists.

/usr/share/man/man3/Text::sprintfn.3pm.gz

Full text search for a certain keyword

If you want full text search, you can use -K option:

$ man -K sprintf

It will open the first manual page for you to read, you can q , and then there will be a prompt:

--Man-- next: gcc-7(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

At this point, you can press Enter to read the next matching manual page, or you can Ctrl-C to exit the man -K state.

other functions

Display the man page in the browser

man -Hfirefox printf

This feature may require the groff command to be searchable in the PATH. So you may need to explicitly install groff :

sudo apt-get install groff

Specify pager (PAGER)

We mentioned that the paging program specified by the environment variable PAGER is used to display the content of the theme, and the default is less. But you can explicitly specify other paging programs as the display tool, which is specified -P

man -P more printf

Convert to plain text, web page or PDF

Plain Text
man printf | col -b > printf.txt
Web page

First, install the software package man2html .

Then use it to convert the man page:

$ man free | man2html -compress -cgiurl man$section/$title.$section$subsection.html > ~/man/free.html

In addition, man2html can also convert man pages into text files that are easy to print:

$ man free | man2html -bare > ~/free.txt

Another way is to do it directly through groff:

zcat `man -w printf` | groff -mandoc -T html > printf.html
PDF

Convert man pages to PDF:

man -t printf | ps2pdf - printf.pdf

The man pages can be printed. It follows the troff format, which is originally a print setting language. After installing ghostscript , you can use the following command to convert the man pages to PDF man -t <manpage> | ps2pdf - <pdf> .

Note that only Times font can be used here, there is no hyperlink, some manuals are converted to terminal design, PS or PDF format does not look normal.

Specify text language

You can install the manpages-zh package to provide Chinese manual page support.

In the terminal, set the LANG environment variable to UTF-8.zh_CN , then man will display the topic chapter content in Chinese. However, if there is no Chinese version, it will fallback to the English version.

If you don’t want to change the environment variables, you can also use the command line parameter -L to achieve the goal, for example

man -L en 5 passwd
man -L zh_CN 5 passwd

Other Information

Where are the man pages stored?

Typical locations are in /usr/share/man and /usr/local/share/man .

In addition, there are often symbolic links /usr/man and /usr/local/man

The manpath command is the correct way to know the exact storage location:

$ manpath
/usr/local/man:/usr/local/share/man:/usr/share/man

The manpath command or the man command uses the /etc/manpath.config or /etc/man_db.conf configuration file to obtain the correct storage location set. But for most people, we don't recommend you to explore these configuration files. They follow certain format conventions, but the analysis and extraction results are often too complicated for shell scripts, and it is far less simple and easy to use than analyzing the results returned by manpath.

To learn /etc/manpath.config , you can check the manual page man manpath .

Sometimes, the $MANPATH$ environment variable may contain the correct value. But in most cases it may be a null value.

Another way is to know indirectly through the whereis command:

$ whereis man
man: /usr/bin/man /usr/local/man /usr/share/man /usr/share/man/man1/man.1.gz /usr/share/man/man7/man.7.gz

/usr/share/man-db/chconfig is a perl execution script that will regenerate /etc/manpath.config , which is a system-level internal behavior.

Use online man pages

Many websites provide online man pages. For a detailed list, see: Wikipedia:Man_page#Repositories_of_manual_pages .

refer to

postscript

Some content in this article is completely copied in the reference link.

🔚


hedzr
95 声望19 粉丝