以前碰到某个命令不会用的时候习惯用–help,这是由于doc和matlab等等这些养成的习惯。最近发现Linux下的man命令要比help详细许多,而且很多时候还给出了例子。最重要的是,help出来的结果往往是一堆堆在了一起,而man出来的则是格式清晰,看着就让人感觉非常舒服。
man即manual(手册),然而在Ubuntu系统中没有默认安装,因此需要自行下载安装:
sudo apt-get install manpages
sudo apt-get install manpages-de
sudo apt-get install manpages-de-dev
sudo apt-get install manpages-dev
我用的系统是CentOS,已经默认安装了manual了。咱们假设已经可以正常使用man命令,继续。
Man Pages(手册页)分为9部分,其中第9个部分不是必须的。
他们分别为:
Executable programs or shell commands——普通的命令
System calls (functions provided by the kernel)——系统调用
Library calls (functions within program libraries)——库函数
Special files (usually found in /dev)——特殊文件
File formats and conventions eg /etc/passwd——文件格式
Games——游戏
Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)——附件和变量
System administration commands (usually only for root)——系统管理用的命令
Kernel routines [Non standard]——内核
我们再看一下man –help的结果:
man [-adfhktwW] [section] [-M path] [-P pager] [-S list]
[-m system] [-p string] name ...
a : find all matching entries
c : do not use cat file
d : print gobs of debugging information
D : as for -d, but also display the pages
f : same as whatis(1)
h : print this help message
k : same as apropos(1)
K : search for a string in all pages
t : use troff to format pages for printing
w : print location of man page(s) that would be displayed
(if no name given: print directories that would be searched)
W : as for -w, but display filenames only
C file : use `file' as configuration file
M path : set search path for manual pages to `path'
P pager : use program `pager' to display pages
S list : colon separated section list
m system : search for alternate system's man pages
p string : string tells which preprocessors to run
e - [n]eqn(1) p - pic(1) t - tbl(1)
g - grap(1) r - refer(1) v - vgrind(1)
man后面可以跟-acdDfhkKtwW这些(至于为什么方括号内与下面的列表不一致,这个我也没有搞懂),跟-C是加文件,加-M是设置man查询文件所在地址,加-P是显示手册的第几页,加-S用冒号隔开部分列表,加-m查询可替换的系统手册页,加-p用字符串操作预处理器
假设最简单的
man read
来查看read这个命令,会看到类似vi编辑器的界面。当然啦,它的快捷命令与vi基本类似。不同之处在于vi可以进入插入模式进行文本改写,而这里不可以,即少了那些用来编辑的命令。
个人感觉用到最多的几个快捷命令是:
f(或键盘上“PgDn”)——向后翻页
b(或键盘上“PgUp”)——向前翻页
d——向后翻半页
u——向前翻半页
g——跳到文章开头
G——跳到文章结尾
退出的操作仍旧是q(quit退出)。
不得不说用了man之后比help舒服了许多。
最后,推荐两个在线查询手册命令的网站:
man.he.net
linux.die.net/man/