man命令是Linux在线参考手册的接口命令,所有的Linux命令都有参考手册,虽然是英文的,但耐心认真的读参考手册,可以学到无穷的知识,也可以解决Linux的大部分问题。
手册分类
最常用的是1用户命令,3(p)库函数,7惯例和协议。
| 分类号 | 内容 |
|---|---|
| 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 |
| p | POSIX Programmer’s Manual |
关于Linux Programmer’s Manual和POSIX Programmer’s Manual的区别,也就是如3和3p的区别,见此。
Basically, the linux manuals are documentation of the commands/APIs from their writers; The POSIX manuals are from the POSIX standard. Usually, the “normal” ones are shorter and terser, but deal with the specific implementation; the POSIX ones are longer and more detailed (see man 3p read), but only tell what is in the standard.
The best is to look in both.
常用参数
-f: 按照完整全名查找手册。其实,是调用whatis命令,用完整名查询whatis数据库。-k: 查询匹配的手册。其实,是调用apropos命令,用字符串匹配whatis数据库。no: no就是分类号码。直接进入命令的对应分类手册。
肌肉训练
1 | $ man -f man # 查询man的手册分类 |
操作按键
| 按键 | 功能 |
|---|---|
| j | 向下 |
| k | 向上 |
| space | 下翻页 |
| PgUp/u | 上翻页 |
| PgDn/d | 下翻页 |
| Home/gg | 第一页 |
| End/G | 最后一页 |
| /string | 向下查找string |
| ?string | 向上查找string |
| n | 下一个 |
| N | 上一个 |
| q | 退出 |
| no | 跳转到no行 |
其他
注意,man命令其实是调用的less命令显示whatis数据库的内容,所以man的按键和less的按键是一样的,而less的命令和vim阅读模式的光标移动的按键是一样的。学了vim后,所有按键都会统一。
CentOS6.6的/etc/man.conf是man的配置文档,MANSECT参数可以设置显示分类的顺序。
CentOS7对应的是/etc/man_db.conf,参数是SECTION。
2017.01.20更新:如果使用man -f或者man -k找不到任何信息,尤其是新系统刚建立的时候,那么是因为whatis数据库尚未建立或更新,请执行如下命令。
CentOS6.6:makewhatis。
CentOS7:mandb。
如果本文对你有所帮助,请小额赞助。
~~ EOF ~~