Linux man --显示在线手册页
用途說明
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、AdministrativeCommands (管理員命令)
?
使用示例
示例一 顯示man的手冊頁
[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] [-Mpathlist] [-P pager] [-B browser] [-H
??????htmlpager] [-S section_list] [section] name ...
?
DESCRIPTION
??????man formats and displays the on-line manual pages.? If you specifysection, man only looks in that? section? of
??????the? manual.? name is normally the name of the manual page, which istypically the name of a command, function,
??????or file.? However, if name contains a slash (/) then man interprets it asa 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 manpages.? Separate the directories with colons.? An
?????????????empty list is the same as not specifying -M at all.? See SEARCH PATH FORMANUAL 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 HTMLfiles.? This option overrides the BROWSER environment variable. By
?????????????default, man uses /usr/bin/less-is,
?
??????-H???? Specify a command that renders HTML files astext.? 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 optionoverrides the MANSECT environ-
?????????????ment variable.
?
??????-a???? By default, man will exit after displaying the firstmanual page it finds.? Using this option forces man
:q
[root@jfht ~]#
?
示例二 顯示C函數printf的手冊頁
[root@jfht ~]# man printf
PRINTF(1)???????????????????????UserCommands??????????????????????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’sManual????????????????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 outputaccording 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() andvsnprintf() write to the character string
??????str.
?
??????The functions vprintf(),? vfprintf(),? vsprintf(),?vsnprintf()? are? equivalent? to? the? functions?printf(),
??????fprintf(),? sprintf(),? snprintf(), respectively, except that theyare 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 stringthat specifies how subsequent argu-
??????ments (or arguments accessed via the variable-length argument facilities ofstdarg(3)) are converted? for? out-
??????put.
?
?? Returnvalue
??????Upon? successful? return,? these? functions return thenumber of characters printed (not including the trailing
??????’\0’ used to end output to strings).? The functions snprintf() andvsnprintf() do? not? write? more? than? size
??????bytes? (including? the? trailing ’\0’).? If the output wastruncated due to this limit then the return value is
??????the number of characters (not including the trailing ’\0’) which would havebeen written to the final string if
[root@jfht ~]#
?
示例三 查找與kill有關的手冊頁
[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 signalprocesses 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 orreport 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 ~]#
?
源文檔 <http://codingstandards.iteye.com/blog/971078>
?
man page
嗄?不知道怎么使用date 這個指令?嘿嘿嘿!不要擔心,我們 Linux 上面的在線求助系統已經都幫您想好要怎么辦了,所以你只要使用簡單的方法去尋找一下說明的內容, 馬上就清清楚楚的知道該指令的用法了!怎么看呢?就是找男人( man ) 呀!?喔!不是啦!這個 man 是 manual (操作說明) 的簡寫啦!只要下達: 『man date』 馬上就會有清楚的說明出現在你面前喔!如下所示:
?
[root@linux ~]#LANG="en"
# 還記得這個咚咚的用意吧?前面提過了,是為了『語系』的需要啊!下達過一次即可!
[root@linux ~]# man date
DATE(1)????????????????????????? UserCommands???????????????????????? DATE(1)
NAME
?????? date - print or set the systemdate and time
SYNOPSIS
?????? date [OPTION]...[+FORMAT]
?????? date [-u|--utc|--universal][MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
?????? Display the current time in thegiven FORMAT, or set the system date.
-d,--date=STRING
????????????? display time described bySTRING, not 'now'
-f,--file=DATEFILE
????????????? like --date once for eachline of DATEFILE
-ITIMESPEC,--iso-8601[=TIMESPEC]
????????????? output? date/time?in ISO 8601 format.? TIMESPEC='date'for date
????????????? only, 'hours', 'minutes',or 'seconds' for date and time to?the
????????????? indicated? precision.??--iso-8601? without TIMESPECdefaults to
????????????? 'date'.
................(略)....
AUTHOR
?????? Written by David MacKenzie.
REPORTINGBUGS
?????? Report bugs to .
COPYRIGHT
?????? Copyright ?2004 Free SoftwareFoundation, Inc.
?????? This is free software; see thesource for copying conditions.? Thereis
?????? NO warranty; not even forMERCHANTABILITY or FITNESS FOR? A? PARTICULAR
?????? PURPOSE.
SEE ALSO
?????? The? full documentation for date is maintained asa Texinfo manual.? If
?????? the info and date programs areproperly installed? at? your?site,? the
?????? command
info coreutils date
should give youaccess to the complete manual.
date (coreutils)5.2.1???????????? May 2005??????????????????????????? DATE(1)
看!馬上就知道一大堆的用法了!如此一來,不就可以知道date 的相關參數了嗎?呵呵!真方便! 而出現的這個屏幕畫面,我們稱呼他為 man page , 您可以在里頭查詢他的用法與相關的參數說明。如果仔細一點來看這個 man page 的話, 您會發現幾個有趣的東西。
?
首先,在上個表格的第一行,您可以看到的是:『DATE(1)』,DATE 我們知道是指令的名稱, 那么 (1) 代表什么呢?他代表的是『一般用戶可使用的指令』的意思!咦!還有這個用意啊!!呵呵! 沒錯~在查詢數據的后面的數字是有意義的喔!他可以幫助我們了解或者是直接查詢相關的資料。 常見的幾個數字的意義是這樣的:
?
?
| 代號 | 代表內容 |
| 1 | 用戶可以操作的指令或可執行文件 |
| 2 | 系統核心可呼叫的函數與工具等 |
| 3 | 一些常用的函數(function)與函式庫(library) |
| 4 | 裝置檔案的說明 |
| 5 | 配置文件或者是某些檔案的格式 |
| 6 | 游戲(games) |
| 7 | 慣例與協議等,例如 Linux 標準文件系統、 網絡協議、ASCII code 等等的說明內容 |
| 8 | 系統管理員可用的管理指令 |
| 9 | 跟 kernel 有關的文件 |
所以,未來您如果使用man page 在察看某些數據時,就會知道該指令/檔案所代表的基本意義是什么了。 舉例來說,如果您下達了 man null 時,會出現的第一行是:『NULL(4)』,對照一下上面的數字意義, 嘿嘿!原來 null 這個玩意兒竟然是一個『裝置檔案』呢!很容易了解了吧!?
?
再來,manpage 的內容也分成好幾個部分來加以介紹該指令呢!就是上頭 man date 那個表格內, 以 NAME 作為開始介紹,最后還有個SEE ALSO 來作為結束。基本上, man page 大致分成底下這幾個部分:
?
?
| 代號 | 內容說明 |
| NAME | 簡短的指令、數據名稱說明 |
| SYNOPSIS | 簡短的指令下達語法(syntax)簡介 |
| DESCRIPTION | 較為完整的說明,這部分最好仔細看看! |
| OPTIONS | 針對 SYNOPSIS 部分中,有列舉的所有可用的參數說明 |
| COMMANDS | 當這個程序(軟件)在執行的時候,可以在此程序(軟件)中下達的指令 |
| FILES | 這個程序或數據所使用或參考或連結到的某些檔案 |
| SEE ALSO | 可以參考的,跟這個指令或數據有相關的其他說明! |
| EXAMPLE | 一些可以參考的范例 |
| BUGS | 是否有相關的臭蟲! |
有時候除了這些外,還可能會看到Authors 與 Copyright 等等,不過也有很多時候僅有 NAME 與 DESCRIPTION 等部分。 通常鳥哥在查詢某個數據時,一定會察看NAME 約略看一下這個數據的意思,再詳看一下 DESCRIPTION ,這個 DESCRIPTION 會提到很多相關的資料與使用時機,從這個地方可以學到很多小細節呢!而如果這個指令其實很熟悉了 (例如上面的 date ),那么鳥哥主要就是查詢關于 OPTIONS 的部分了!可以知道每個參數的意思, 這樣就可以下達比較細部的指令內容呢!最后,鳥哥會再看一下,啊跟這個資料有關的還有哪些東西可以使用的? 舉例來說,上面的 SEE ALSO 就告知我們還可以利用『info coreutils date』來進一步查閱數據, 某些說明內容還會列舉有關的檔案(FILES 部分) 來提供我們參考!這些都是很有幫助的!
?
好了,大致上了解了man page 的內容后,那么,在 man page 當中我還可以利用哪些按鍵來幫忙查閱呢? 首先,如果要向下翻頁的話,可以按下鍵盤的 空格鍵 ,也可以使用 [PageUp] 與[Page Down] 來翻頁呢!同時,如果您知道某些關鍵詞的話, 那么可以在任何時候輸入『 /word 』,來主動搜尋關鍵詞!例如在上面的搜尋當中, 我輸入了 /date 會變成怎樣?
?
DATE(1)????????????????????????? User Commands???????????????????????? DATE(1)
NAME
?????? date - print or set the systemdate and time
SYNOPSIS
?????? date [OPTION]...[+FORMAT]
?????? date [-u|--utc|--universal][MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
?????? Display the current time in thegiven FORMAT, or set the system date.
...........(中間省略)........
/date
看到了嗎?您按下『/』之后,光標應該就會移動到屏幕的最下面一行,并等待您輸入搜尋的字符串了。此時,輸入 date 后, man page 就會開始搜尋跟 date 有關的字符串, 并且移動到該區域呢!很方便吧!最后,如果要離開 man page 時,直接按下『 q 』就能夠離開了。 我們將一些在 man page 常用的按鍵給他整理整理:
?
?
| 按鍵 | 進行工作 |
| 空格鍵 | 向下翻一頁 |
| [Page Down] | 向下翻一頁 |
| [Page Up] | 向上翻一頁 |
| [Home] | 去到第一頁 |
| [End] | 去到最后一頁 |
| /string | 向『下』搜尋 string 這個字符串,如果要搜尋 vbird 的話,就輸入 /vbird |
| ?string | 向『上』搜尋 string 這個字符串 |
| n, N | 利用 / 或 ? 來搜尋字符串時,可以用 n 來繼續下一個搜尋 (不論是 / 或 ?) ,可以利用 N 來進行『反向』搜尋。舉例來說,我以 /vbird 搜尋 vbird 字符串, 那么可以 n 繼續往下查詢,用 N 往上查詢。若以 ?vbird 向上查詢 vbird 字符串, 那我可以用 n 繼續『向上』查詢,用 N 反向查詢。 |
| q | 結束這次的 man page |
要注意喔!上面的按鍵是在man page 的畫面當中才能使用的! 比較有趣的是那個搜尋啦!我們可以往下或者是往上搜尋某個字符串,例如要在 man page 內搜尋 vbird 這個字符串, 可以輸入 /vbird 或者是 ?vbird ,只不過一個是往下而一個是往上來搜尋的。而要 重復搜尋 某個字符串時,可以使用 n 或者是 N 來動作即可呢! 很方便吧!^_^
?
既然有man page ,自然就是因為有一些文件數據,所以才能夠以 man page 來讀出來啰! 那么這些 man page的數據 放在哪里呢?不同的distribution 通常可能有點差異性,不過,通常是放在 /usr/share/man 這個目錄里頭,然而,我們可以透過修改他的 man page 搜尋路徑來改善這個目錄的問題!修改/etc/man.config ( 有的版本為 man.conf 或 manpath.conf) 即可啰!至于更多的關于 man 的訊息您可以使用『 manman 』來查詢呦!關于更詳細的設定,我們會在 Shell 的章節當中繼續的說明喔!
?
man還有一些有趣的使用方式呢!舉例來說,如果您還想要知道更多跟 man 有較相關的訊息, 可以下達:
?
[root@linux ~]# man-f man
man????????????????? (1)? - format and display the on-line manualpages
man????????????????? (7)? - macros to format man pages
man.conf [man]?????? (5)? - configuration data for man
看到了嗎?使用-f 的參數,可以取得更多的 man 的相關信息,而上頭這個表格當中,也有提示了 (數字) 的內容, 舉例來說,第二行的『 man(7) 』表示有個 man (7) 的說明文件存在喔!但是卻有個 man (1) 存在啊! 那當我們下達『 man man 』的時候,到底是找到哪一個說明檔呢?嘿嘿!混亂了吧?! 其實,您可以指定不同的文件的,舉例來說,上表當中的兩個 man 您可以這樣將他的文件叫出來:
?
[root@linux~]# man 1 man? <==這里是用 man(1) 的文件數據
[root@linux ~]# man 7 man? <==這里是用 man(7) 的文件數據
你可以自行將上面兩個指令輸入一次看看,就知道,兩個指令輸出的結果是不同的。那個1, 7 就是分別取出在 man page 里面關于 1 與 7 相關數據的文件檔案啰! 好了,那么萬一我真的忘記了下達數字,只有輸入『 man man 』時,那么取出的數據到底是 1 還是 7 啊? 這個就跟搜尋的順序有關了。搜尋的順序是記錄在 /etc/man.conf 這個配置文件當中, 先搜尋到的那個說明檔,就會先被顯示出來! 一般來說,通常會先找到數字較小的那個啦!因為排序的關系啊!所以, man man 會跟 man 1 man 結果相同! 這樣說,可以明白了嗎?!
?
除此之外,我們還可以利用『關鍵詞』找到更多的說明文件數據喔!例如:
?
[root@linux ~]# man-k man
. [builtins]???????? (1)? - bash built-in commands, seebash(1)
alias [builtins]???? (1)? - bash built-in commands, seebash(1)
........(中間省略)....
xsm????????????????? (1x)? - X Session Manager
zshall?????????????? (1)? - the Z shell meta-manpage
zshbuiltins????????? (1)? - zsh built-in commands
zshzle?????????????? (1)? - zsh command line editor
看到了吧!很多對吧!因為這個是利用關鍵詞將說明文件里面只要含有man 那個字眼的(不見得是完整字符串) 就將他取出來!很方便吧! ^_^
?
事實上,還有兩個指令與man page 有關呢!而這兩個指令是 man 的簡略寫法說~ 就是這兩個:
?
[root@linux~]# whatis? [指令或者是數據]?? <==相當于 man -f [指令或者是數據]
[root@linux ~]# apropos [指令或者是數據]?? <==相當于 man -k [指令或者是數據]
?
總結
以上是生活随笔為你收集整理的Linux man --显示在线手册页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P1658 购物
- 下一篇: syslinux引导硬盘linux,使用