man 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

man 命令安装:


-bash: man: command not found

#Debian
apt-get install man-db

#Ubuntu
apt-get install man-db

#Alpine
apk add man

#Arch Linux
pacman -S util-linux
 
#Kali Linux
apt-get install man-db

#CentOS
yum install man

#Fedora
dnf install man-db

#Raspbian
apt-get install man-db

#Docker
docker run cmd.cat/man man

man 命令补充说明:


man 命令是 Linux 下的帮助指令,通过 man 指令可以查看 Linux 中的指令帮助、配置文件帮助和编程帮助等信息。

man 命令语法:


man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] 
    [-m system[,...]] [-M path] [-S list] [-e extension] [-i|-I] 
    [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] 
    [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] 
    [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] 
    [[section] page ...] ...
man -k [apropos options] regexp ...
man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
man -f [whatis options] page ...
man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] 
    [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] 
    [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ...
man -w|-W [-C file] [-d] [-D] page ...
man -c [-C file] [-d] [-D] page ...
man [-hV]

man 命令选项:


-a:在所有的man帮助手册中搜索;
-f:等价于whatis指令,显示给定关键字的简短描述信息;
-P:指定内容时使用分页程序;
-M:指定man手册搜索的路径。

man 命令参数:


数字:指定从哪本man手册中搜索帮助;
关键字:指定要搜索帮助的关键字。

man 命令实例


查看手册页中的 man 命令。

[www@localhost commandnotfound]$ man man
MAN(1)                                                                                Manual pager utils                                                                               MAN(1)

NAME
       man - an interface to the on-line reference manuals

SYNOPSIS
       man  [-C  file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m system[,...]] [-M path] [-S list] [-e extension] [-i|-I] [--regex|--wildcard] [--names-only] [-a] [-u]
       [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file
       ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-?V]

DESCRIPTION
       man  is the system's manual pager. Each page argument given to man is normally the name of a program, utility or function.  The manual page associated with each of these arguments is
       then found and displayed. A section, if provided, will direct man to look only in that section of the manual.  The default action is to search in all of the available sections,  fol‐
       lowing a pre-defined order and to show only the first page found, even if page exists in several sections.

       The table below shows the section numbers of the manual followed by the types of pages they contain.

       1   Executable programs or shell commands
       2   System calls (functions provided by the kernel)
       3   Library calls (functions within program libraries)
       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 [Non standard]

       A manual page consists of several sections.

       Conventional  section  names include NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS,
       EXAMPLE, AUTHORS, and SEE ALSO.

       The following conventions apply to the SYNOPSIS section and can be used as a guide in other sections.

       bold text          type exactly as shown.
       italic text        replace with appropriate argument.
       [-abc]             any or all arguments within [ ] are optional.
       -a|-b              options delimited by | cannot be used together.
       argument ...       argument is repeatable.
       [expression] ...   entire expression within [ ] is repeatable.

       Exact rendering may vary depending on the output device.  For instance, man will usually not be able to render italics when running in a terminal, and will typically  use  underlined
       or coloured text instead.

       The  command  or function illustration is a pattern that should match all possible invocations.  In some cases it is advisable to illustrate several exclusive invocations as is shown
       in the SYNOPSIS section of this manual page.

EXAMPLES
       man ls
           Display the manual page for the item (program) ls.

       man -a intro
           Display, in succession, all of the available intro manual pages contained within the manual.  It is possible to quit between successive displays or skip any of them.

       man -t alias | lpr -Pps
           Format the manual page referenced by `alias', usually a shell manual page, into the default troff or groff format and pipe it to the printer named ps.   The  default  output  for
           groff is usually PostScript.  man --help should advise as to which processor is bound to the -t option.

       man -l -Tdvi ./foo.1x.gz > ./foo.1x.dvi
           This  command will decompress and format the nroff source manual page ./foo.1x.gz into a device independent (dvi) file.  The redirection is necessary as the -T flag causes output
           to be directed to stdout with no pager.  The output could be viewed with a program such as xdvi or further processed into PostScript using a program such as dvips.
 Manual page man(1) line 1 (press h for help or q to quit)

man 命令的坑


我们输入 man ls,它会在最左上角显示 LS(1),在这里,LS 表示手册名称,而 (1) 表示该手册位于第一节章,同样,我们输 man ifconfig 它会在最左上角显示 IFCONFIG(8)。也可以这样输入命令: man [章节号] 手册名称

man 是按照手册的章节号的顺序进行搜索的,比如:

man sleep

只会显示 sleep 命令的手册,所以,如果想查看库函数 sleep,就要输入:

man 3 sleep

man 命令扩展阅读:




man 命令评论