手册页中的数字是什么意思?

Wil*_*uck 622 man

因此,例如,当我输入时,man ls我看到LS(1). 但是,如果我输入man apachectl我会看到APACHECTL(8),如果我输入man cd我最终会看到cd(n).

我想知道括号中数字的意义是什么(如果有的话)。

Mic*_*zek 650

该数字对应于该页面来自手册的哪个部分;1 是用户命令,而 8 是系统管理员的东西。man 本身的手册页 ( man man) 对其进行了解释并列出了标准的:

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 Daemons

    Distributions customize the manual section to their specifics,
    which often include additional sections.
Run Code Online (Sandbox Code Playgroud)

有些术语在不同的部分有不同的页面(例如,printf作为命令出现在第 1 部分,作为stdlib函数出现在第 3 部分);在这种情况下,您可以将部分编号传递到man页面名称之前以选择您想要的页面,或用于man -a连续显示每个匹配的页面:

$ man 1 printf
$ man 3 printf
$ man -a printf
Run Code Online (Sandbox Code Playgroud)

您可以判断一个术语属于哪些部分man -k(相当于apropos命令)。它也会进行子字符串匹配(例如,它会sprintf在您运行时显示man -k printf),因此您需要使用^term来限制它:

$ man -k '^printf'
printf               (1)  - format and print data
printf               (1p)  - write formatted output
printf               (3)  - formatted output conversion
printf               (3p)  - print formatted output
printf [builtins]    (1)  - bash built-in commands, see bash(1)
Run Code Online (Sandbox Code Playgroud)

请注意,该部分有时可以包括子部分(例如,pin1p3pabove)。该p小节是针对 POSIX 规范的;该x小节用于 X Window 系统文档。

  • 请注意,这些部分编号适用于 Linux。AFAIK 的所有 unix 变体中的 1、3 和 6 都相同,但其他部分和非单数部分可能不同。通常“man X intro”描述了“X”部分中的内容。 (13认同)
  • 这当然可以解释。是否有一种简单的方法可以判断给定命令是否有多个手册页? (7认同)
  • 嗯,谁想到你需要一本手册才能使用手册......直到现在我从来没有执行过`man man`......直到现在。 (7认同)
  • @KeithB:我使用了一些具有不同 4、5、7、8 的 unice。Digital Unix (OSF1) 有,Solaris 仍然有:文件格式为 4,misc 为 5,设备为 7。Solaris 还将管理员命令放在 1m 中。我认为 2 中的系统调用是通用的,但有些系统在 2 中也有一些 C 库接口(当它们应该是同名系统调用的薄包装器时)。 (3认同)
  • @Wil 是的,已编辑 (2认同)
  • `man -w -a` 将显示所有版本的联机帮助页的路径,而不显示它们。 (2认同)
  • 或:来自 man 1.6 的 `$ whatis printf`(而不是 'man -k "^printf"') (2认同)
  • 遗憾的是,'man man' 并未列出每个平台上的部分。(看着你,OS X。)我们是否应该将其合并到其他很好的答案中? (2认同)

Kei*_*thB 65

这些章节编号的历史可以追溯到Thompson 和 Ritchie 在 1971 年的原始Unix 程序员手册

原来的部分是

  1. 命令
  2. 系统调用
  3. 子程序
  4. 特殊文件
  5. 文件格式
  6. 用户维护的程序
  7. 各种各样的


Bab*_*yan 39

konqueror 还描述了非标准部分:(感谢@greg0ire 的想法)

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    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
Run Code Online (Sandbox Code Playgroud)


Sla*_*hin 25

它的含义已经描述过,但我还想补充一点,每个部分都有带有介绍的特殊手册页:intro。例如,参见man 1 introman 3 intro等等。


Sha*_*dur 17

man联机帮助页:

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 conven?
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]
Run Code Online (Sandbox Code Playgroud)

至于为什么他们像这样分开——有一些重叠。根据您的意思,某些联机帮助页存在于多个部分中。

例如,man crontabman 5 crontab--比较可能是后者是您要查找的那个。


gre*_*ire 9

这些是节号。只需输入man man或打开 konqueror 并输入 man://man,您就会看到这些部分是什么。


max*_*zig 9

通常,手册页是通过用括号括起来的部分作为后缀来引用的,例如:

read(2)
Run Code Online (Sandbox Code Playgroud)

这种风格有两个主要优点:

  • 很明显你引用了一个手册页——也就是说,你可以写一些类似 'cf. read(3)' 而不是 'cf. 阅读的第 3 部分手册页'
  • 如果多个部分包含具有相同名称的手册页,则指定该部分会更精确

手册页按部分组织,例如,第 1 部分包含所有用户命令手册页,第 2 部分包含系统调用的所有手册页,第 3 部分包含库函数等。

在命令行上,如果您没有明确指定您将获得第一个匹配手册页的部分,则采用默认的部分遍历顺序,例如:

$ man read
Run Code Online (Sandbox Code Playgroud)

BASH_BUILTINS(1)在 Fedora 上显示。在哪里

$ man 2 read
Run Code Online (Sandbox Code Playgroud)

显示read()系统调用的手册页。

请注意,该部分的位置规范是不可移植的——例如,在 Solaris 上,您可以像这样指定它:

$ man -s 2 read
Run Code Online (Sandbox Code Playgroud)

通常,man man还会列出一些可用的部分。但不一定是全部。为了列出所有可用的部分,可以列出默认 man 路径或环境变量中列出的所有目录的子目录$MANPATH。例如在安装了一些开发包的 Fedora 23 系统上/usr/share/man有以下子目录:

cs  es  id  man0p  man2   man3x  man5x  man7x  man9x  pt_BR  sk  zh_CN
da  fr  it  man1   man2x  man4   man6   man8   mann   pt_PT  sv  zh_TW
de  hr  ja  man1p  man3   man4x  man6x  man8x  pl     ro     tr
en  hu  ko  man1x  man3p  man5   man7   man9   pt     ru     zh
Run Code Online (Sandbox Code Playgroud)

带有man前缀的目录代表每个部分 - 而其他目录包含翻译的部分。因此,要获取非空部分的列表,可以发出如下命令:

$ find /usr/share/man -type f  | sed 's@^.*/man\(..*\)/.*$@\1@' \
    | sort -u | column
0p  1p  3   4   6   8
1   2   3p  5   7
Run Code Online (Sandbox Code Playgroud)

(以 结尾的部分p是 POSIX 手册页)

要查看另一种语言的手册页(如果可用),可以设置与语言相关的环境变量,例如:

$ LC_MESSAGES=de_DE man read
Run Code Online (Sandbox Code Playgroud)

此外,每个部分都应该有一个名为 的介绍手册页intro,例如可以通过以下方式查看:

$ man 2 intro
Run Code Online (Sandbox Code Playgroud)


sch*_*ily 5

SVr4 的定义是:

1 User Commands
2 System Calls
3 library Functions
4 File Formats
5 Standards, Environment and Macros (e.g. man(5))
6 Games and Demos
7 Device and Network Interfaces, Special Files
8 Maintenance Procedures
9 Kernel and Driver entry points and structures
Run Code Online (Sandbox Code Playgroud)

这些是“遗传”UNIX 的实际编号。POSIX 没有定义数字。