Unix命令手册中括号内的数字代表什么意思?

662
例如:man(1)find(3)updatedb(2)?括号中的数字代表什么意思(英国称之为“括号”)?

8
手册页面将提供一些介绍,使用以下命令查看(man 1 intro)(man 2 intro)。 - tsenapathy
10
在“Super User”和“Unix and Linux”这两个网站上有一篇类似的问题:“Unix命令或C函数后括号和数字的含义是什么?” - Franklin Yu
7个回答

627

这是分配给命令的手册页部分。

它们被分为:

  1. 通用命令
  2. 系统调用
  3. C库函数
  4. 特殊文件(通常是设备,位于/dev目录中)和驱动程序
  5. 文件格式和约定
  6. 游戏和屏幕保护程序
  7. 杂项
  8. 系统管理命令和守护进程

每个部分的原始描述可以在Unix程序员手册(第二页)中查看。

要访问名为“foo(5)”的手册页,请运行:

man 5 foo

6
在一些(大多数、所有?)系统中,man foo.5同样有效,并且在你必须在上一个命令给出错误页面后指定页码时更容易添加页码。 - 12431234123412341234123

99

命令所在的章节在手册中有详细介绍。章节列表在man手册中有记录。例如:

man 1 man
man 3 find

当不同部分存在相似或完全相等的命令时,这很有用。


127
在“旧时代”,手册页的章节编号对应着纸质版手册所在的活页夹。 - Darron

67

章节编号之所以重要,是因为在很多年前,磁盘空间比现在更加紧缺,各个章节可以单独安装。

例如,许多系统仅安装了1和8。如今人们倾向于通过谷歌查找命令。


39

正如@Ian G所说,它们是man手册的章节。然而,让我们更深入地了解一下:

1. 使用man man命令查看man手册,并显示9个章节如下:

DESCRIPTION
       man  is  the system's manual pager. Each page argument given
       to man is normally the name of a program, utility  or  func‐
       tion.   The  manual page associated with each of these argu‐
       ments 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 sec‐
       tions following a pre-defined order ("1 n l 8 3 2 3posix 3pm
       3perl 5 4 9 6 7" by default, unless overridden by  the  SEC‐
       TION directive in /etc/manpath.config), 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 fol‐
       lowed 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]

       A manual page consists of several sections.


2. man <section_num> <cmd>

假设你正在搜索Linux命令,你找到了在线的OPEN(2)页面: open(2) — Linux 手册页

要在你的电脑上查看man页面,请输入man 2 open

对于FOPEN(3),使用man 3 fopen等。

3. man <section_num> intro

要阅读每个部分的介绍页面,请输入man <section_num> intro,例如man 1 introman 2 introman 7 intro等。

要依次查看所有man页面的介绍页面,请执行man -a intro。将打开第一个部分的介绍页面,按q退出后,按Enter查看第二个部分的介绍页面,以此类推。每次按下q后,将回到主终端屏幕,但您仍将处于交互式提示状态,并且将看到此行:

--Man-- next: intro(8) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
请注意,man -a intro 命令列出的章节顺序如下:
  1. 第 1 章
  2. 第 8 章
  3. 第 3 章
  4. 第 2 章
  5. 第 5 章
  6. 第 4 章
  7. 第 6 章
  8. 第 7 章
这个搜索顺序是有意为之的,正如man man页面所解释的那样:
The default action is to search in all of the available sections follow‐
ing a pre-defined order ("1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7" by default, unless overrid‐
den  by the SECTION directive in /etc/manpath.config)
他们为什么选择这个顺序?我不知道(如果您知道,请在评论中回答),但是请注意这个顺序是正确和有意的。

相关:

  1. 关于"linux what does the number mean in parenthesis after a function?"的谷歌搜索结果
  2. SuperUser: 一个 Unix 命令或者 C 函数后面的括号和数字代表什么?
  3. Unix & Linux: man 手册中的数字代表什么?

4
非常有用的信息,不确定为什么会有负评,但我给你加上一票。 - harperville
2
优秀的补充 - 一个当之无愧的 +1 - Manuel Jordan

11
请注意,在其他的UNIX系统中,指定章节的方法可能会有所不同。例如,在Solaris系统中,可以使用以下方式:
man -s 1 man

9

该指示命令所在的man手册部分。man命令的-s开关可以用于将搜索限制为某些部分。

当您查看man页面时,左上角显示了部分名称,例如:

用户命令 printf(1)
标准C库函数 printf(3C)

因此,如果您想查找C函数并且不想意外地看到与其同名的用户命令页面,则应执行'man -s 3C ...'


4
以下是关于手册章节的维基百科详细信息:

维基百科

手册章节分为以下几类:
  1. 常规命令
  2. 系统调用
  3. 库函数,特别是 C 标准库
  4. 特殊文件(通常是设备文件,位于 /dev 目录中)和驱动程序
  5. 文件格式和约定
  6. 游戏和屏幕保护程序
  7. 杂项
  8. 系统管理命令和守护进程

4
这个回答已经没用了;之前已经被接受的回答中包含的链接也失效了并且被删除了,所以现在这个回答没有添加任何内容。 - Ben Voigt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接