本文链接:http://codingstandards.iteye.com/blog/971078 (转载请注明出处)
man命令是个常用的命令,如果你稍微熟悉Unix/Linux系统的话,它用来显示在线手册页,是获取命令、函数、配置文件等的帮助信息的重要手段,另外一个手段是info命令。manpage就是手册页,它有一定的编写格式,Linux系统在文档方面是做得相当不错的,这给我们使用Linux提供了方便。shell内置命令的手册页,显示的是bash全部内置命令的手册页,可以采用help命令来获取内置命令的帮助信息。
格式:man <cmd>
显示<cmd>命令的手册页。默认情况下,man命令使用less作为显示文档的命令。
手册页的操作指令:
按q退出,这个最重要,因为Ctrl+C都没法退出来
按下箭头可以往后一行
按回车或者上箭头可以往前一行
按End键可以翻到最后一页
按Home键可以翻到第一页
按空白键或者PgDn键可以往后翻一页
按PgUp键可以往前翻一页
输入/keyword回车可以搜索keyword
输入?keyword回车可以往前搜索keyword
按n可以往前或往后搜索下一个
格式:man -k <cmd>
格式:apropos <cmd>
显示与<cmd>有关的手册页列表。
格式:man 1 <cmd>
显示<cmd>命令的手册页。
格式:man 2 <syscall>
显示系统调用<syscall>的手册页。
格式:man <section> <name>
显示<name>指定章节<section>的手册页,其中<section>包括
1、Standard commands (标准命令)
2、System calls (系统调用)
3、Library functions (库函数)
4、Special devices (设备说明)
5、File formats (文件格式)
6、Games and toys (游戏和娱乐)
7、Miscellaneous (杂项)
8、Administrative Commands (管理员命令)
[root@jfht ~]# man man
man(1) man(1)
NAME
man - format and display the on-line manual pages
SYNOPSIS
man [-acdfFhkKtwW] [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P pager] [-B browser] [-H
htmlpager] [-S section_list] [section] name ...
DESCRIPTION
man formats and displays the on-line manual pages. If you specify section, man only looks in that section of
the manual. name is normally the name of the manual page, which is typically the name of a command, function,
or file. However, if name contains a slash (/) then man interprets it as a file specification, so that you can
do man ./foo.5 or even man /cd/foo/bar.1.gz.
See below for a description of where man looks for the manual page files.
OPTIONS
-C config_file
Specify the configuration file to use; the default is /etc/man.config. (See man.config(5).)
-M path
Specify the list of directories to search for man pages. Separate the directories with colons. An
empty list is the same as not specifying -M at all. See SEARCH PATH FOR MANUAL PAGES.
-P pager
Specify which pager to use. This option overrides the MANPAGER environment variable, which in turn
overrides the PAGER variable. By default, man uses /usr/bin/less -is.
-B Specify which browser to use on HTML files. This option overrides the BROWSER environment variable. By
default, man uses /usr/bin/less-is,
-H Specify a command that renders HTML files as text. This option overrides the HTMLPAGER environment
variable. By default, man uses /bin/cat,
-S section_list
List is a colon separated list of manual sections to search. This option overrides the MANSECT environ-
ment variable.
-a By default, man will exit after displaying the first manual page it finds. Using this option forces man
:q
[root@jfht ~]#
[root@jfht ~]# man printf
PRINTF(1) User Commands PRINTF(1)
NAME
printf - format and print data
SYNOPSIS
printf FORMAT [ARGUMENT]...
printf OPTION
DESCRIPTION
Print ARGUMENT(s) according to FORMAT.
--help display this help and exit
--version
output version information and exit
FORMAT controls the output as in C printf. Interpreted sequences are:
\" double quote
\NNN character with octal value NNN (1 to 3 digits)
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
:q
注:上面显示的是命令printf的手册页,但不是C函数printf的手册页。
[root@jfht ~]# man 3 printf
PRINTF(3) Linux Programmer’s Manual PRINTF(3)
NAME
printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - formatted output conversion
SYNOPSIS
#include <stdio.h>
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
#include <stdarg.h>
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
DESCRIPTION
The functions in the printf() family produce output according to a format as described below. The functions
printf() and vprintf() write output to stdout, the standard output stream; fprintf() and vfprintf() write out-
put to the given output stream; sprintf(), snprintf(), vsprintf() and vsnprintf() write to the character string
str.
The functions vprintf(), vfprintf(), vsprintf(), vsnprintf() are equivalent to the functions printf(),
fprintf(), sprintf(), snprintf(), respectively, except that they are called with a va_list instead of a vari-
able number of arguments. These functions do not call the va_end macro. Consequently, the value of ap is unde-
fined after the call. The application should call va_end(ap) itself afterwards.
These eight functions write the output under the control of a format string that specifies how subsequent argu-
ments (or arguments accessed via the variable-length argument facilities of stdarg(3)) are converted for out-
put.
Return value
Upon successful return, these functions return the number of characters printed (not including the trailing
’\0’ used to end output to strings). The functions snprintf() and vsnprintf() do not write more than size
bytes (including the trailing ’\0’). If the output was truncated due to this limit then the return value is
the number of characters (not including the trailing ’\0’) which would have been written to the final string if
[root@jfht ~]#
[root@jfht ~]# man -k kill
kill (1) - terminate a process
kill (1p) - terminate or signal processes
kill (2) - send signal to a process
kill (3p) - send a signal to a process or a group of processes
kill [builtins] (1) - bash built-in commands, see bash(1)
killall (1) - kill processes by name
killchar [curs_termattrs] (3x) - curses environment query routines
killpg (2) - send signal to a process group
killpg (3) - send signal to all members of a process group
killpg (3p) - send a signal to a process group
killwchar [curs_termattrs] (3x) - curses environment query routines
mysql_waitpid (1) - kill process and wait for its termination
mysql_zap (1) - kill processes that match a pattern
pkill [pgrep] (1) - look up or signal processes based on name and other attributes
pthread_kill (3p) - send a signal to a thread
skill (1) - send a signal or report process status
snice [skill] (1) - send a signal or report process status
tgkill (2) - Send signal sig to one specific thread, tgid
tkill (2) - send a signal to a single process
xkill (1x) - kill a client by its X resource
yes (1) - output a string repeatedly until killed
[root@jfht ~]#
1. manpage是由哪些部分组成的?
2. manpage的语法规则如何,以及如何变成man手册页?
【1】飞诺网 linux man的使用
http://dev.firnow.com/course/6_system/linux/Linuxjs/2008109/149569.html
【2】Linux公社 Linux man章节分类以及查询
http://www.linuxidc.com/Linux/2010-12/30881.htm
【3】三二一@小鱼 (9)linux man usage
http://blog.csdn.net/livelylittlefish/archive/2009/08/26/4487971.aspx
【4】我使用过的Linux命令之apropos - 根据关键字搜索命令
http://codingstandards.iteye.com/blog/776024
【5】我使用过的Linux命令之help - 显示Bash内建命令的帮助信息
http://codingstandards.iteye.com/blog/804620
【6】我使用过的Linux命令之type - 显示命令的类型
http://codingstandards.iteye.com/blog/831504