man page简介

    使用man命令,查看的就是man page,man就是manual(手册)的缩写。man page按照文档主题的不同,分成9个部分。输入man 7 man可以看到这9个部分的描述。

# man 7 man

MANUAL SECTIONS:
1    Commands            用户命令
2    System calls            系统调用
3    Library calls                         库函数调用
4    Special files                         特殊文件/设备
5    File formats and conventions      文件格式
6    Games                                游戏
7    Conventions and miscellaneous     惯例、协议等杂项
8    System management commands   系统管理命令
9    Kernel routines                      内核相关文件(这项已经不用了,在CentOS6.4中就没了)

    所以使用man的时候,要根据需求,查看不同的section,例如要查看库函数的printf的时候,就要man 3 printf。而查看作为命令的printf的用法的时候,就man 1 printf或者man printf,man命令默认是查看最低的那个section的。

    如果想知道要查看的命令有哪些section怎么办?可以使用whatis command。例如:

# whatis printf

printf               (1)  - format and print data
printf               (1p)  - write formatted output
printf               (3)  - formatted output conversion
printf               (3p)  - print formatted output
printf [builtins]    (1)  - bash built-in commands, see bash(1)

    可以看到有五行输出结果,中间括号里面的数字就是我们想要知道的该命令包含多少sections了。其中有个p的那些,指的是POSIX(可移植操作系统接口)。最后一行指的是,还有个作为bash内建命令的printf,想要查看这个printf的用法,就要看bash的文档。

    使用man -f command和whatis command等价。


    现在说一下man文档的内容,man文档大概由下面这些部分组成。

NAME                名字:简要说明命令的作用
SYNOPSIS           摘要:命令语法的简介,如果是函数,还会说明包含在哪个头文件中
DESCRIPTION        描述:命令的详细介绍
OPTIONS               选项:列举所有可用的参数
EXAMPLES         例子
AUTHOR                作者
REPORTING BUGS  已知错误
COPYRIGHT           版权
SEE ALSO             与这个命令相关的其他参考说明

    下面是一个例子。

# man ls


LS(1)                            User Commands                           LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -a, --all
              do not ignore entries starting with .

       -A, --almost-all
              do not list implied . and ..

       --author
              with -l, print the author of each file

       -l     use a long listing format

       -r, --reverse
              reverse order while sorting

       -t     sort by modification time
……

AUTHOR
       Written by Richard Stallman and David MacKenzie.

REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.

COPYRIGHT
       Copyright © 2006 Free Software Foundation, Inc.
       This is free software.  You may redistribute copies  of  it  under  the
       terms       of       the      GNU      General      Public      License
       <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY,  to  the
       extent permitted by law.

SEE ALSO
       The  full  documentation  for ls is maintained as a Texinfo manual.  If
       the info and ls programs are properly installed at your site, the  com-
       mand

              info ls

       should give you access to the complete manual.

ls 5.97                            July 2009                             LS(1)
(END)



    第一行显示这是哪个section的。下面的就是描述了,NAME一栏说明,ls这个命令是用来列出目录所包含的内容的。

    语法那一栏:

ls [OPTION]... [FILE]...

    中括号表示里面的内容是可选的,不填也可以。也就是说,OPTION可以不填,FILE也可以不填,只输入ls也可以用。就像这样:

# ls

    这样默认就是列出当前目录的内容。

    [OPTION]里面可以选的参数就在下面的说明中,这份文档没有OPTION这一项,都写在DESCRIPTION那里了。参数有两种格式,像"--all"这样的长格式,和"-a"这样的短格式。

    用法就是这样:

# ls --all

# ls -a

    短格式的参数可以写在一起,例如下面两种写法是一样的。

# ls -a -l

# ls -al

    [FILE]就是指命令的对象,这里就是ls要查看的目录,可以查看多个,用空格分开。例如:

# ls /tmp /home


    一般我们用man主要就是查看命令的作用和有什么参数,因此都着重查看DESCRIPTION和OPTION。有的命令其man page很长,这时候就需要查找功能了。按一下“/”,然后再输入要查找的内容,按回车,就可以看到结果了,按"n"和"N"可以查看下一个或者上一个搜索结果。

    在man page中,按空格键,Page Up和Page Down都可以翻页,按Home和End是到最第一页和最后一页。

    最后,按q就可以退出了。

posted on 2013-07-27 15:19  香菜炒饭  阅读(832)  评论(0)    收藏  举报