什么是man?
man是系统的用户手册。你可以在shell中直接敲入man XXX,得到关于这个命令、工具和函数的说明。没错,你可以查询Linux下函数的用法,如pthread_create、open、socket等系统相关API,非常方便和全面,唯一一个不友好的地方是全英文,需要我们好好学学英语。
手册所属类别如果有对应的手册存在,那么将会直接进入浏览界面。每一个手册都有对应的数字说明其所属的类别。
数字含义1Executable programs or shell commands2System calls (functions provided by the kernel)3Library calls (functions within program libraries)4Special files (usually found in /dev)5File formats and conventions, e.g. /etc/passwd6Games7Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)8System administration commands (usually only for root)9Kernel routines [Non standard]8表示需要管理员权限才能运行,最常见的就是sudo apt get xxx(8);像是常见的ls mkdir等,都是属于可执行程序(1)。
手册页都有什么内容?一个手册有多个部分组成。典型的部分有: NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RE‐TURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and SEE ALSO.
- NAME 命令名称及其一句话描述
- SYNOPSIS 摘要
- DESCRIPTION 描述
- OPTION 选项
- EXAMPLE 例子
不过,不是所有的手册页都是按照这样组织的,如ls命令选项则是出现在DESCRIPTION中的。有一些约定是我们必须知道的,这有助于我们理解这个手册的内容。
形式含义粗体强调正在解释的内容斜体需要用合适的参数替换,ubuntu渲染成下划线[-abc]可选参数(可以为空)-a|-b|分隔的不能同时使用的参数argument …可重复参数,也就是可以叠加?[expression] …[ ]内参数是可重复的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.查找我们需要的信息
man手册使用less命令来浏览、定位、查找等任务。这里只列举一些常见的操作:
查找SEARCHING /pattern * Search forward for (N-th) matching line. ?pattern * Search backward for (N-th) matching line. n * Repeat previous search (for N-th occurrence). N * Repeat previous search in reverse direction. ESC-n * Repeat previous search, spanning files. ESC-N * Repeat previous search, reverse dir. & spanning files. ESC-u Undo (toggle) search highlighting. &pattern * Display only matching lines
假如我们需要查找nm的-C选项是做什么的:
- man nm
- /C
- f b查看有没有对应的内容
如果你只对部分内容感兴趣,你可以试试&pattern
只显示匹配的行。