Hacker News 中文摘要

RSS订阅

man页面标题中的数字,例如sleep(3) -- Number in man page titles e.g. sleep(3)

文章摘要

Linux手册页标题中的数字(如sleep(3))表示不同的手册章节编号,每个数字对应特定类型的文档内容。例如,1代表可执行程序或shell命令,2代表系统调用,3代表库函数等。这有助于区分同名但类型不同的命令或函数。

文章总结

今日小知识:man手册标题中的数字含义(如sleep(3))

作者Lalit Maganti分享了一个关于Linux man手册标题中数字含义的发现。这些数字出现在诸如sleep(3)read(2)等命令的man手册标题中,代表手册的不同章节分类:

  1. 章节编号含义
    • 1:可执行程序或shell命令
    • 2:系统调用(由内核提供的函数)
    • 3:库调用(程序库中的函数)
    • (其他较少见的章节编号)

作者通过一个代码审查中的注释意识到这个细节,发现basename应该查阅man 3 basename而非man 2 basename,因为前者是libc库调用而非系统调用。

  1. 额外知识点
    • 数字后可能带有字母后缀表示特殊类型:
      • p表示POSIX手册页(如free(3p)
      • x表示X文档(如ncurses(3x)

作者自嘲虽然使用man手册多年,但直到现在才真正理解这些数字的含义。

(原文发布于2025年11月17日,包含作者个人博客链接和社交媒体分享选项,此处从略)

评论总结

总结评论内容如下:

  1. 对man命令的幽默态度

    • 有用户调侃阅读man手册后会产生写文章的冲动 "Step 1: Read man man Step 2: Feel the urge to write an article about that" (LtWorf)
    • 有用户分享man手册中的趣味彩蛋 "You can tune a file system, but you cannot tune a fish" (beej71)
  2. 关于man手册使用习惯的变化

    • 部分用户承认已转向使用Stack Overflow和LLMs "I think I haven't read manpages since stackoverflow" (amelius)
    • 但也有用户怀念传统方式 "I'm feeling old now" (pfdietz)
  3. 关于man手册章节编号的讨论

    • 有用户指出重要但少用的章节编号 "One very important section number is 5" (gerikson)
    • 有用户分享章节编号可以不限于数字 "TCL man pages use the 'n' section" (PhilipRoman)
  4. man手册的历史渊源

    • 有用户详细解释章节编号源于AT&T System V UNIX的物理装订手册 "they identified physical binders in the series published by AT&T" (throwanem)
  5. man手册的实际应用

    • 有用户推荐第3章节的实用价值 "For me man(3) is the most interesting of them all" (s20n)
    • 有用户提供POSIX标准手册链接 "The POSIX standard manual pages can be found here" (chasil)
  6. 使用man手册的困扰

    • 有用户表示会立即忘记章节编号含义 "always forget it immediately" (kykat)
    • 有用户吐槽man手册的困惑性 "millions of hours lost by confused folks" (et1337)