Linux下man命令的使用技巧
在Linux的shell下我經(jīng)常要使用man命令來查看一些不熟悉的命令的使用方法。最經(jīng)在shell下編程的時候,發(fā)現(xiàn)一些c和c++中的庫函數(shù)不清楚,我都跑去網(wǎng)上搜索了。一不小心,我發(fā)現(xiàn),原來man還可以用來查詢系統(tǒng)庫文件中的一些函數(shù)定義和使用方法。
man就是manual的縮寫,用來查看系統(tǒng)中自帶的各種參考手冊,但是手冊頁分為好幾個部分,如下所示:
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
在shell中輸入 man+數(shù)字+命令/函數(shù) 即可以查到相關的命令和函數(shù)。若不加數(shù)字,那man命令默認從數(shù)字較小的手冊中尋找相關命令和函數(shù)。
例如,本來是想尋找c標準庫中的rand()函數(shù),直接使用man rand得到的是一個rand命令的手冊,直接用來產(chǎn)生一個隨機數(shù),這個內(nèi)容在手冊section 1中。如果使用man 3 rand就可以得到自己想要的庫函數(shù)中rand()的用法了。
【編輯推薦】