爱技术 & 爱分享
爱蛋蛋 & 爱生活

man命令

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

man:是manual(手册)的缩写。在输入命令有困难时,可以立刻得到这个文档。例如, 如果使用ps命令时遇到困难,可以输入man ps得到帮助信息,此时会显示出ps的手册页(man page)。

由于手册页man page是用less程序来显示的, 所以在man page里可以使用less的所有选项。

用法如下

usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]
[-m system] [-p string] name ...

  a : find all matching entries
  c : do not use cat file
  d : print gobs of debugging information
  D : as for -d, but also display the pages
  f : same as whatis(1)
  h : print this help message
  k : same as apropos(1)
  K : search for a string in all pages
  t : use troff to format pages for printing
  w : print location of man page(s) that would be displayed
      (if no name given: print directories that would be searched)
  W : as for -w, but display filenames only

  C file   : use 'file' as configuration file
  M path   : set search path for manual pages to 'path'
  P pager  : use program 'pager' to display pages
  S list   : colon separated section list
  m system : search for alternate system's man pages
  p string : string tells which preprocessors to run
               e - [n]eqn(1)   p - pic(1)    t - tbl(1)
               g - grap(1)     r - refer(1)  v - vgrind(1)

参数:

-C config_file:指定设定文件man.conf,缺省值是/etc/man.conf。

-M path:指定了联机手册的搜寻路径, 如果没有指定则使用环境变数MANPATH的设定;如果没有使用MANPATH, 则会使用/usr/lib/man.conf内的设定;如果MANPATH是空字串,则表示使用缺省值。

-P pager:指定使用何种pager.man会优先使用此选项设定,然后是依环境变数MANPAGER设定,然后是环境变数PAGER;man缺省使用/usr/bin/less -is。

-S section_list man:所搜寻的章节列表(以冒号分隔),此选项会覆盖环境变数MANSECT的设定。

-a man:缺省情况是在显示第一个找到的手册之后,就会停止搜寻,使用此选项会强迫man继续显示所有符合name的联机手册。

-c:即使有最新的cat page,也继续对联机手册重新作排版,本选项在屏幕的行列数改变时或已排版的联机手册损坏时特别有意义。

-d:不要真的显示联机手册,只显示除错讯息。

-D:同时显示联机手册与除错讯息。

-h:显示求助讯息然后结束程式 。

-K:对所有的联机手册搜寻所指定的字串。请注意,本功能回应速度可能很慢,如果指定section(区域)会对速度有帮助。

-m system:依所指定的system名称而指定另一组的联机手册。

然后我们使用man man来查看一下man命令的详细信息

这个例子会显示 man 命令的 man 帮助页,这将先解压 man 帮助页文件,然后解释格式化指令并用 less 显示结果,所以导航操作和在 less 中一样。

NAME
       man - format and display the on-line manual pages

SYNOPSIS
       man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list] [section] name ...

DESCRIPTION
       man  formats and displays the on-line manual pages.  If you specify section, man only looks in that section of the manual.  name is normally the name of the manual page, which is typically the name of a command, function, or file.  How-
       ever, if name contains a slash (/) then man interprets it as a file specification, so that you can do man ./foo.5 or even man /cd/foo/bar.1.gz.

       See below for a description of where man looks for the manual page files.

MANUAL SECTIONS
       The standard sections of the manual include:

       1      User Commands

       2      System Calls

       3      C Library Functions

       4      Devices and Special Files

       5      File Formats and Conventions

       6      Games et. Al.

       7      Miscellanea

       8      System Administration tools and Deamons

       Distributions customize the manual section to their specifics, which often include additional sections.

OPTIONS
       -C  config_file
              Specify the configuration file to use; the default is /etc/man.config.  (See man.config(5).)

       -M  path
              Specify the list of directories to search for man pages.  Separate the directories with colons.  An empty list is the same as not specifying -M at all.  See SEARCH PATH FOR MANUAL PAGES.

       -P  pager
              Specify which pager to use.  This option overrides the MANPAGER environment variable, which in turn overrides the PAGER variable.  By default, man uses /usr/bin/less -is.

       -B     Specify which browser to use on HTML files.  This option overrides the BROWSER environment variable. By default, man uses /usr/bin/less-is,

       -H     Specify a command that renders HTML files as text.  This option overrides the HTMLPAGER environment variable. By default, man uses /bin/cat,

       -S  section_list
              List is a colon separated list of manual sections to search.  This option overrides the MANSECT environment variable.

       -a     By default, man will exit after displaying the first manual page it finds.  Using this option forces man to display all the manual pages that match name, not just the first.
       -c     Reformat the source man page, even when an up-to-date cat page exists.  This can be meaningful if the cat page was formatted for a screen with a different number of columns, or if the preformatted page is corrupted.

       -d     Do not actually display the man pages, but do print gobs of debugging information.

       -D     Both display and print debugging info.

       -f     Equivalent to whatis.

       -F or --preformat
              Format only - do not display.

       -h     Print a help message and exit.

       -k     Equivalent to apropos.

       -K     Search for the specified string in *all* man pages. Warning: this is probably very slow! It helps to specify a section.  (Just to give a rough idea, on my machine this takes about a minute per 500 man pages.)

       -m  system
              Specify an alternate set of man pages to search based on the system name given.

       -p  string
              Specify the sequence of preprocessors to run before nroff or troff.  Not all installations will have a full set of preprocessors.  Some of the preprocessors and the letters used to designate them are: eqn (e), grap (g), pic  (p),
              tbl (t), vgrind (v), refer (r).  This option overrides the MANROFFSEQ environment variable.

       -t     Use /usr/bin/groff -Tps -mandoc to format the manual page, passing the output to stdout.  The default output format of /usr/bin/groff -Tps -mandoc is Postscript, refer to the manual page of /usr/bin/groff -Tps -mandoc for ways to
              pick an alternate format.

       Depending on the selected format and the availability of printing devices, the output may need to be passed through some filter or another before being printed.

       -w or --path
              Do not actually display the man pages, but do print the location(s) of the files that would be formatted or displayed. If no argument is given: display (on stdout) the list of directories that is searched by man for man pages.  If
              manpath is a link to man, then "manpath" is equivalent to "man --path".

       -W     Like -w, but print file names one per line, without additional information.  This is useful in shell commands like man -aW man | xargs ls -l

CAT PAGES
       Man  will  try to save the formatted man pages, in order to save formatting time the next time these pages are needed.  Traditionally, formatted versions of pages in DIR/manX are saved in DIR/catX, but other mappings from man dir to cat
       dir can be specified in /etc/man.config.  No cat pages are saved when the required cat directory does not exist.  No cat pages are saved when they are formatted for a line length different from 80.  No cat pages are saved when  man.con-
       fig contains the line NOCACHE.

       It  is possible to make man suid to a user man. Then, if a cat directory has owner man and mode 0755 (only writable by man), and the cat files have owner man and mode 0644 or 0444 (only writable by man, or not writable at all), no ordi-
       nary user can change the cat pages or put other files in the cat directory. If man is not made suid, then a cat directory should have mode 0777 if all users should be able to leave cat pages there.

       The option -c forces reformatting a page, even if a recent cat page exists.

HTML PAGES
       Man will find HTML pages if they live in directories named as expected to be ".html", thus a valid name for an HTML version of the ls(1) man page would be /usr/share/man/htmlman1/ls.1.html.

SEARCH PATH FOR MANUAL PAGES
       man uses a sophisticated method of finding manual page files, based on the invocation options and environment variables, the /etc/man.config configuration file, and some built in conventions and heuristics.

       First of all, when the name argument to man contains a slash (/), man assumes it is a file specification itself, and there is no searching involved.
       But in the normal case where name does not contain a slash, man searches a variety of directories for a file that could be a manual page for the topic named.

       If you specify the -M pathlist option, pathlist is a colon-separated list of the directories that man searches.

       If you do not specify -M but set the MANPATH environment variable, the value of that variable is the list of the directories that man searches.

       If you do not specify an explicit path list with -M or MANPATH, man develops its own path list based on the contents of the configuration file /etc/man.config.  The MANPATH statements in the configuration file identify particular  direc-
       tories to include in the search path.

       Furthermore,  the MANPATH_MAP statements add to the search path depending on your command search path (i.e. your PATH environment variable).  For each directory that may be in the command search path, a MANPATH_MAP statement specifies a
       directory that should be added to the search path for manual page files.  man looks at the PATH variable and adds the corresponding directories to the manual page file search path.  Thus, with the proper use  of  MANPATH_MAP,  when  you
       issue the command man xyz, you get a manual page for the program that would run if you issued the command xyz.

       In addition, for each directory in the command search path (we will call it a "command directory") for which you do not have a MANPATH_MAP statement, man automatically looks for a manual page directory "nearby" namely as a subdirectory in
       the command directory itself or in the parent directory of the command directory.

       You can disable the automatic "nearby" searches by including a NOAUTOPATH statement in /etc/man.config.

       In each directory in the search path as described above, man searches for a file named topic.section, with an optional suffix on the section number and possibly a compression suffix.  If it does not find such a file, it then looks in any
       subdirectories  named  manN  or catN where N is the manual section number.  If the file is in a catN subdirectory, man assumes it is a formatted manual page file (cat page).  Otherwise, man assumes it is unformatted.  In either case, if
       the filename has a known compression suffix (like .gz), man assumes it is gzipped.

       If you want to see where (or if) man would find the manual page for a particular topic, use the --path (-w) option.

ENVIRONMENT
       MANPATH
              If MANPATH is set, man uses it as the path to search for manual page files.  It overrides the configuration file and the automatic search path, but is overridden by the -M invocation option.  See SEARCH PATH FOR MANUAL PAGES.

       MANPL  If MANPL is set, its value is used as the display page length.  Otherwise, the entire man page will occupy one (long) page.

       MANROFFSEQ
              If MANROFFSEQ is set, its value is used to determine the set of preprocessors run before running nroff or troff.  By default, pages are passed through the tbl preprocessor before nroff.

       MANSECT
              If MANSECT is set, its value is used to determine which manual sections to search.

       MANWIDTH
              If MANWIDTH is set, its value is used as the width manpages should be displayed.  Otherwise the pages may be displayed over the whole width of your screen.

       MANPAGER
              If MANPAGER is set, its value is used as the name of the program to use to display the man page.  If not, then PAGER is used. If that has no value either, /usr/bin/less -is is used.

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

       HTMLPAGER
              The command to use for rendering HTML manual pages as text.  If it is not set, /bin/cat is used.

       LANG   If LANG is set, its value defines the name of the subdirectory where man first looks for man pages. Thus, the command 'LANG=dk man 1 foo' will cause man to look for the foo man page in .../dk/man1/foo.1, and  if  it  cannot  find
              such a file, then in .../man1/foo.1, where ... is a directory on the search path.

       NLSPATH, LC_MESSAGES, LANG
       MANPL  If MANPL is set, its value is used as the display page length.  Otherwise, the entire man page will occupy one (long) page.

       MANROFFSEQ
              If MANROFFSEQ is set, its value is used to determine the set of preprocessors run before running nroff or troff.  By default, pages are passed through the tbl preprocessor before nroff.

       MANSECT
              If MANSECT is set, its value is used to determine which manual sections to search.

       MANWIDTH
              If MANWIDTH is set, its value is used as the width manpages should be displayed.  Otherwise the pages may be displayed over the whole width of your screen.

       MANPAGER
              If MANPAGER is set, its value is used as the name of the program to use to display the man page.  If not, then PAGER is used. If that has no value either, /usr/bin/less -is is used.

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

       HTMLPAGER
              The command to use for rendering HTML manual pages as text.  If it is not set, /bin/cat is used.

       LANG   If LANG is set, its value defines the name of the subdirectory where man first looks for man pages. Thus, the command 'LANG=dk man 1 foo' will cause man to look for the foo man page in .../dk/man1/foo.1, and  if  it  cannot  find
              such a file, then in .../man1/foo.1, where ... is a directory on the search path.

       NLSPATH, LC_MESSAGES, LANG
              The  environment  variables  NLSPATH and LC_MESSAGES (or LANG when the latter does not exist) play a role in locating the message catalog.  (But the English messages are compiled in, and for English no catalog is required.)  Note
              that programs like col(1) called by man also use e.g. LC_CTYPE.

       PATH   PATH helps determine the search path for manual page files.  See SEARCH PATH FOR MANUAL PAGES.

       SYSTEM SYSTEM is used to get the default alternate system name (for use with the -m option).

BUGS
       The -t option only works if a troff-like program is installed.
       If you see blinking \255 or <AD> instead of hyphens, put 'LESSCHARSET=latin1' in your environment.

TIPS
       If you add the line

        (global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))

       to your .emacs file, then hitting F1 will give you the man page for the library call at the current cursor position.

       To get a plain text version of a man page, without backspaces and underscores, try

         # man foo | col -b > foo.mantxt

AUTHOR
       John W. Eaton was the original author of man.  Zeyd M. Ben-Halim released man 1.2, and Andries Brouwer followed up with versions 1.3 thru 1.5p.  Federico Lucifredi <flucifredi@acm.org> is the current maintainer.

SEE ALSO
       apropos(1), whatis(1), less(1), groff(1), man.config(5).

有一些命令不是系统命令,而是 Bash 特有的,比如 alias 和 cd。这些 Bash 特有的命令可以在 BASH_BUILTINS man 帮助页中查看,和上面的比起来它们的描述更加精炼,不过内容都是类似的。

所有的 man 帮助页都应该显示这些子段落:Name、 Synopsis、 Description、Examples、See、Also。有些还会添加一些额外的子段落,比如 Options、 Exit、Status、 Environment、Bugs、Files、Author、Reporting、Bugs、History、Copyright。

名称 说明
NAME 命令的名称及简要说明
DESCRIPTION 命令功能的详细描述
OPTIONS 所支持的选项的相关说明
SYNOPSIS 使用格式
EXAMPLES 使用示例
NOTES 相关注意事项
FILES 相关的配置文件
SEE ALSO 相关参考

我们输入man ls,它会在最左上角显示“LS(1)”,在这里,“LS”表示手册名称,而“(1)”表示该手册位于第一节章,同样,我们输man ifconfig它会在最左上角显示“IFCONFIG(8)”。

而且man是按照手册的章节号的顺序进行搜索的,而且遇到第一个符合的命令之后就返回。

man sleep 只会显示sleep命令的手册

如果想查看库函数sleep,就要输入:man 3 sleep

如果需要查看在man命令中的帮助,只需要输入H或h即可。

关于man手册的章节信息,请看此处man手册章节

参考文章:https://linux.cn/article-8722-1.html

赞(0) 传送门
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。编程日志 » man命令
分享到: 更多 (0)

游戏 && 后端

传送门传送门