Linux 命令行完全指南:man 命令
man 命令
man命令是Linux系統(tǒng)中最核心的命令之一,因為通過該命令,可以查看其他Linux命令的使用信息。當(dāng)然了,man命令不僅可以查看命令的使用幫助,還可以查看軟件服務(wù)配置文件、系統(tǒng)調(diào)用、庫函數(shù)等的幫助信息。

語法格式:
man [選項] 參數(shù)選項 | 說明 |
-a | 在所有的man幫助手冊中搜索; |
-k | 查看和命令相關(guān)的所有幫助或者使用 apropos 命令; |
-f | 等價于whatis指令,顯示給定關(guān)鍵字的簡短描述信息和查看命令擁有哪個級別的幫助; |
-P | 指定內(nèi)容時使用分頁程序; |
-M | 指定man手冊搜索的路徑; |
參數(shù) | |
數(shù)字 | 指定從哪本man手冊中搜索幫助; |
關(guān)鍵字 | 指定要搜索幫助的關(guān)鍵字; |
man命令的參數(shù)選項及具體說明如下表所示:
級別 | 說明 |
1 | 普通用戶可以執(zhí)行的系統(tǒng)命令和可執(zhí)行文件; |
2 | 系統(tǒng)內(nèi)核可調(diào)用的函數(shù)與工具等; |
3 | 一些常用的函數(shù)(function)與函數(shù)庫(library),大部分為C的函數(shù)庫(libc); |
4 | 設(shè)備文件說明,通常在/dev下的文件; |
5 | 配置文件或某些文件格式; |
6 | 游戲的幫助(個人版的Linux中是有游戲的); |
7 | 慣例與協(xié)議等,如Linux文件系統(tǒng),網(wǎng)絡(luò)協(xié)議,ASCII code等說明; |
8 | 系統(tǒng)管理員可用的管理命令; |
9 | 跟kernel有關(guān)的文件; |
當(dāng)我們使用man命令查詢各命令所對應(yīng)的幫助時,幫助內(nèi)容中的標(biāo)題格式所對應(yīng)的含義如下表所示:
標(biāo)題 | 功能說明 |
NAME | 命令說明及介紹; |
SYNOPSIS | 命令的基本使用語法; |
DESCRIPTION | 命令使用詳細(xì)描述,以及相關(guān)參數(shù)選項說明,有的命令會單獨(dú)使用參數(shù)選項,例如分開介紹COMMAND LINE OPTIONS 或 OPTIONS; |
OPTIONS | 命令相關(guān)參數(shù)選項說明(有的命令幫助沒有此選項); |
COMMANDS | 在執(zhí)行這個程序(軟件)的時候,可以在此程序(軟件)中執(zhí)行的 =命令; |
FILES | 程序涉及(或使用或關(guān)聯(lián))的相關(guān)文件; |
EXAMPLES | 命令的一些例子,這有時很有用; |
SEE ALSO | 和命令相關(guān)的信息說明; |
BUGS (REPORTING BUGS) | 命令對應(yīng)缺陷問題的描述; |
COPYRIGHT | 版權(quán)信息相關(guān)聲明; |
AUTHOR | 作者介紹; |
執(zhí)行man命令進(jìn)入到man幫助頁面中,實際上就相當(dāng)于是瀏覽一個文本文件,可以利用下表中的快捷鍵快速瀏覽查閱想要查找的內(nèi)容。
操作鍵 | 說明 |
PgUp | 向上翻一頁 |
PgDn | 向下翻一頁 |
Home或g | 跳轉(zhuǎn)到第一頁 |
End或G | 跳轉(zhuǎn)到最后一頁 |
上箭頭 | 向上移動一行 |
下箭頭 | 向下移動一行 |
/字符串 | 從當(dāng)前頁向下搜索字符串 |
?字符串 | 從當(dāng)前頁向上搜索字符串 |
n,N | 當(dāng)時有/或?符號向下或向上搜索時,使用n會繼續(xù)當(dāng)前所搜方向的下一個匹配的查詢,使用N時則進(jìn)行相反方向的查詢;例如: /opsbugs向下搜索后,再按n則會繼續(xù)向下搜索opsbugs,而按N就會反向向上搜索opsbugs了;同理使用?opsbugs向上搜索后,在按n就會繼續(xù)向上搜索opsbugs,而按N就會反向向下搜索opsbugs |
q | 退出,結(jié)束此次man幫助 |
man命令也包含了很多其他的參數(shù),但是在實際工作中幾乎是用不到的,如果有需要使用man的特殊參數(shù),那么可以使用man man命令進(jìn)行查閱。
案例演示
(1) 查看passwd命令擁有哪些級別的幫助
[root@localhost ~]# man -f passwd
sslpasswd (1ssl) - compute password hashes
passwd (1) - update users authentication tokens
#說明passwd是級別1的幫助
[root@localhost ~]# whatis passwd
sslpasswd (1ssl) - compute password hashes
passwd (1) - update user's authentication tokens注意: 有的時候在新裝完系統(tǒng)或恢復(fù)快照之后使用whatis命令會報錯,這是因為數(shù)據(jù)庫沒有更新的原因,執(zhí)行makewhatis命令更新下數(shù)據(jù)庫即可。
(2) 查看ls命令的幫助信息
[root@localhost ~]# 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 is specified.
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
Manual page ls(1) line 1 (press h for help or q to quit)我們輸入man ls,它會在最左上角顯示“LS(1)”,在這里“LS”表示手冊名稱,而“(1)”表示該手冊位于第一節(jié)章,man是按照手冊的章節(jié)號的順序進(jìn)行搜索的;也可以這樣輸入命令: man [章節(jié)號] 手冊名稱,如: man 5 passwd和man 1 passwd。
(3) 查看和ls命令相關(guān)的所有幫助,查找所有命令中包含passwd關(guān)鍵字的文件,不常用。
[root@localhost ~]# man -k passwd
chgpasswd (8) - update group passwords in batch mode
chpasswd (8) - update passwords in batch mode
gpasswd (1) - administer /etc/group and /etc/gshadow
grub2-mkpasswd-pbkdf2 (1) - Generate a PBKDF2 password hash.
lpasswd (1) - Change group or user password
pam_localuser (8) - require users to be listed in /etc/passwd
passwd (1) - update user's authentication tokens
sslpasswd (1ssl) - compute password hashes
pwhistory_helper (8) - Helper binary that transfers password hashes from passwd or shadow to opasswd

























