在Linux的shell下我經常要使用man命令來查看一些不熟悉的命令的使用方法。最經在shell下編程的時候,發現一些c和c++中的庫函數不清楚,我都跑去網上搜索了。一不小心,我發現,原來man還可以用來查詢系統庫文件中的一些函數定義和使用方法。
man就是manual的縮寫,用來查看系統中自帶的各種參考手冊,但是手冊頁分為好幾個部分,如下所示:
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+數字+命令/函數 即可以查到相關的命令和函數。若不加數字,那man命令默認從數字較小的手冊中尋找相關命令和函數。
例如,本來是想尋找c標准庫中的rand()函數,直接使用man rand得到的是一個rand命令的手冊,直接用來產生一個隨機數,這個內容在手冊section 1中。如果使用man 3 rand就可以得到自己想要的庫函數中rand()的用法了。