前言
小生認為一切指令的學習首先要從幫助入手,深入了解它的功能,即使是在實際項目中我們都離不開它的幫助。因為我們不一定能夠記住全部指令的全部的相關功能,因此,查看指令的幫助是我們的不二選擇。
正文
下面,我們就來看看 man 和 info 這兩個指令。
首先,我們可以通過 man man指令來查看相關說明。可能有的朋友英語不算很好,又想盡快的掌握linux指令,我們可以下載中文man幫助手冊,安裝后設置別名(如cman),使用其便可顯示中文(安裝過程請關注下一篇博客)。不過,小生建議不要過度依賴中文手冊,讀懂英文文獻才是王道。
man(1) NAME man - format and display the on-line manual pagesMANUAL SECTIONS The standard sections of the manual include: 1 User Commands //標準指令---用戶在shell環境中可以執行的指令或可執行文件 2 System Calls //系統調用---由內核提供的函數 (open,write之類,查看頭文件) 3 C Library Functions //C 函數 ---(PRintf,fread) 4 Devices and Special Files //設備和特殊文件說明 ---通常在/dev下的文件 5 File Formats and Conventions //文件格式和約定 ---配置文件或者是某些文件的格式 比如passwd 6 Games et. Al. //游戲等娛樂 ---給游戲留的,由各個游戲自己定義 7 Miscellanea // 雜項 ---例如man、environ、Linux文件系統、網絡協議、ASCII code等說明 8 System Administration tools and Deamons //系統管理員可用的管理命令---ifconfig
例如 :
[linux@linux ~]$ man printf --左上角默認PRINTF(1),是shell中的指令 [linux@linux ~]$ man 3 printf --代表C語言中的函數
man page 主要分為以下幾個部分
| NAME | 簡短的指令、數據名稱說明 |
| SYNOPSIS | 指令下達語法簡介 |
| DESCRipTION | 詳盡完整的說明!! |
| AUTHOR | 作者 |
| REPORTING BUGS | 反饋錯誤 |
| COPYRIGHT | 版權 |
| SEE ALSO | 與指令相關的其他說明 |
幫助文檔中相關按鍵的說明
| 按鍵 | 相應的動作 |
| SPACE | 向下翻頁 |
| Page Down | 向下翻頁 方向鍵↓ 向下移動 |
| Page Up | 向上翻頁 方向鍵↑ 向上移動 |
| Home | 回到首頁 |
| End | 轉到最后一頁 |
| /string | 向下搜尋字符串 |
| ?string | 向上搜尋字符串 |
| n , N | 查看下一個或上一個搜尋到的字符串,與/string、?string配合使用 |
| q | 退出 |
查看以關鍵字開頭的所有說明文件
1 [linux@linux ~]$ man -f man2 man (1) - format and display the on-line manual pages3 man (1p) - display system documentation4 man (7) - macros to format man pages5 man.config [man] (5) - configuration data for man6 man [manpath] (1) - format and display the on-line manual pages7 man-pages (7) - conventions for writing Linux man pages
根據關鍵字(不一定開頭)顯示出相關說明文檔
1 [linux@linux ~]$ man -k man2 ...3 xsetwacom (1) - commandline utility to query and modify wacom driver settings4 xsltproc (1) - command line XSLT processor5 yum-groups-manager (1) - create and edit yum's group metadata
執行后發現最后一列中有man關鍵字的也會列舉出來,這不是我們想要的,因此我想到鳥哥在后面章節所用到的截取命令(cut 、grep),這就是第一遍讀書的效果,知道有相關的命令,然后去查找、去實現。
1 [linux@linux ~]$ man -k man | cut -d ' ' -f 1 | grep 'man'2 cmakecommands3 command4 command5 ecryptfs-manager6 ...
在man中還可以執行指令 ---- !指令
關于man的相關參數說明我參考了http://www.CUOXin.com/chengmo 的博客,現引用在下。
使用語法:
man [-adfhktwW] [section] [-M path] [-P pager] [-S list] [-m system] [-p string] title..
參數用法:
| 參數 | 備注 |
| man命令常用參數 | |
| -a | 顯示所有匹配項 |
| -d | 顯示man查照手冊文件時候,搜索路徑信息,不顯示手冊頁內容 |
| -D | 同-d,顯示手冊頁內容 |
| -f | 同命令whatis ,將在whatis數據庫查找以關鍵字開同的幫助索引信息 |
| -h | 顯示幫助信息 |
| -k | 同命令apropos 將搜索whatis數據庫,模糊查找關鍵字 |
| -S list | 指定搜索的領域及順序 如:-S 1:1p httpd 將搜索man1然后 man1p目錄 |
| -t | 使用troff 命令格式化輸出手冊頁 默認:groff輸出格式頁 |
| -w | 不帶搜索title 打印manpath變量 帶title關鍵字 打印找到手冊文件路徑,默認搜索一個文件后停止 |
| -W | 同-w |
| section | 搜索領域【限定手冊類型】默認查找所有手冊 |
| man命令其它參數 | |
| -c | 顯示使用 cat 命令的手冊信息 |
| -C | 指定man 命令搜索配置文件 默認是man.config |
| -K | 搜索一個字符串在所有手冊頁中,速度很慢 |
| -M | 指定搜索手冊的路徑 |
| -P pro | 使用程序pro顯示手冊頁面 默認是less |
| -B pro | 使用pro程序顯示HTML手冊頁 默認是less |
| -H pro | 使用pro程序讀取HTML手冊,用txt格式顯示,默認是cat |
| -p str | 指定通過groff格式化手冊之前,先通過其它程序格式化手冊 |
實例代碼
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 [chengmo@centos5 ~]$man-wpasswd/usr/share/man/man1/passwd.1.gz#顯示passwd幫助文件路徑,passwd.1 通過名稱知道這個是passwd命令幫助手冊,那它的其它命令的呢?[chengmo@centos5 ~]$man-awpasswd/usr/share/man/man1/passwd.1.gz/usr/share/man/man5/passwd.5.gz#加入-a獲得所有幫助手冊文件地址,默認只會查找一個[chengmo@centos5 ~]$man5passwd#只得到passwd配置文件幫助信息,可以加入領域類型限制,如果知道5,默認是查詢man5 文件配置信息說明 手冊目錄[chengmo@centos5 ~]$man-dpasswdReading configfile/etc/man.config.....foundmandirectory/usr/manusing/usr/bin/less-is as pagerusing/usr/bin/less-is as browserusing/bin/catto dump HTML pages as textpath directory/binisinthe configfileadding/usr/share/man/zh_CNto manpathadding/usr/share/manto manpathfound'NROFF_OLD_CHARSET'inpathold charset of'/usr/share/man/man1/passwd.1.gz'is'ISO-8859-1'man:not executingcommand:(cd/usr/share/man&& (echo".ll 11.8i";echo".nr LL 11.8i";echo".pl 1100i";/usr/bin/gunzip-c'/usr/share/man/man1/passwd.1.gz';echo".///"";echo".pl /n(nlu+10") |/usr/bin/gtbl|/usr/bin/nroff-c --legacy ISO-8859-1 -mandoc 2>/dev/null|/usr/bin/less-is)#man -d 返回man 執行過程搜索查找方法,以及查詢手冊通過怎么樣格式化語句顯示。都會列出來#可以看到,指定pages,borwser輸出命令對應文件,html輸出文件,搜索路徑,由于我當前LANG=zh_CN.gb2312因此,添加了zh_CN目錄搜索#最終執行命令時候,通過一系列格式轉換命令,最終有less顯示[chengmo@centos5 ~]$man-S 1:2passwd#在領域類型是:1:2 范圍內查找手冊,對應目錄分別是man1 ,man2[chengmo@centos5 ~]$man-f httpdhttpd (8) - Apache Hypertext Transfer Protocol Serverhttpd (rpm) - Apache HTTP Serverhttpd-devel (rpm) - Development toolsforthe Apache HTTP server.#在whatis數據庫(有所有網站man幫助以及cat,doc幫助信息索引)中查詢,文件標題以:http開頭信息的文檔#中間的(8) 對應我們可以用:man 8 httpd 調用,對于顯示(rpm)實際上顯示有個httpd幫助信息,是屬于一個httpd rpm安裝包,通過man rpm httpd查看不了。可以通過rpm -ql httpd 查找安裝包[chengmo@centos5 ~]$man-k httpdCGI::Carp (3pm) - CGI routinesforwriting to the HTTPD (or other) error loghttpd (8) - Apache Hypertext Transfer Protocol Serverhttpd (rpm) - Apache HTTP Serverhttpd-devel (rpm) - Development toolsforthe Apache HTTP server.httpd_selinux (8) - Security Enhanced Linux Policyforthe httpd daemonlighttpd (1) - a fast, secure and flexible webserverlighttpd (rpm) - Lightning fast webserver with light system requirementslighttpd-fastcgi (rpm) - FastCGI module and spawning helperforlighttpd and php configurationncsa_auth (8) - NCSA httpd-style passWordfileauthentication helperforSquid#在whatis數據庫中,查詢包含httpd所有幫助手冊,以及安裝包. 可以通過:rpm -ql lighttpd[chengmo@centos5 ~]$ rpm -ql lighttpd |grepgz/usr/share/man/man1/lighttpd.1.gz#其實這個包剛好是:lighttpd (1) - a fast, secure and flexible webserver 幫助手冊[chengmo@centos5 ~]$man-w/usr/kerberos/man:/usr/local/share/man:/usr/share/man/zh_CN:/usr/share/man:/usr/local/man#顯示man 命令查找手冊的路徑對于:whatis數據庫,以及中文化linux幫助文件這里先不分析。
一般遇到一個不是很熟悉命令可以先通過:
man -k command1 查詢所有類似幫助文件信息,這樣輸出最多也可以用:
man -f command1 查詢以command1開頭所有相關幫助信息列表 如果發現有類似:command1 (5)
man 5 command1 通過直接定位5獲得幫助信息
info
以主題的形式把幾個命令組織在一起,以便于我們閱讀,在主題內以node(節點)的形式把本主題的幾個命令串聯在一起。因為小生對info命令并不是很了解,在這里就不過多涉獵,等到哪天認識到它的真諦,還會回來補全介紹。
主要快捷鍵設置如下
| 按鍵 | 相應的動作 |
| Space | 向下翻頁 |
| Page Down | 向下翻頁 |
| Page Up | 向上翻頁 |
| tab | 在node間切換,有node的地方,通常會以*顯示 |
| Enter | 當光標在node上時,按下Enter進入該node |
| b | 移動光標到該info畫面當中的第一個node處 |
| e | 移動光標到該info畫面當中的最后一個node處 |
| n | 切換到下一個node |
| p | 切換到上一個node |
| u | 向上移動一層 |
| s(/) | 在info page中進行搜尋 |
| h | 顯示求助選單 |
| ? | 指令一覽表 |
| q | 退出 |
如果有重要的知識點沒有提到,還請各位在評論中指出,我會根據建議再次維護,盡量做到盡善盡美!謝謝
本文版權歸作者所有,歡迎轉載,且在文章頁面明顯位置給出原文鏈接
新聞熱點
疑難解答