Linux系:manコマンド使ってみよう!
私は、普段の開発はほぼLinuxで行っています。
その際に、「コマンドのオプションなんだっけ?」とか、「関数の引数なんだっけ?」と思うことがあります。
インターネットで調べるのも有りですが、ぱっと調べられるので使えるようになっていると便利です。
manコマンドでmanを調べる
manコマンドでmanについても調べることができます。
$ man man
以下はページャで出力されます。
MAN(1) マニュアルページユーティリティー MAN(1) 名前 man - an interface to the system reference manuals 書式 man [man options] [[section] page ...] ... man -k [apropos options] regexp ... man -K [man options] [section] term ... man -f [whatis options] page ... man -l [man options] file ... man -w|-W [man options] page ... 説明 man is the system's manual pager. Each page argument given to man is normally the name of a program, utility or function. The manual page associated with each of these arguments is then found and displayed. A section, if provided, will direct man to look only in that section of the manual. The default action is to search in all of the available sections following a pre-defined order (see DEFAULTS), and to show only the first page found, even if page exists in several sections. 次の表はマニュアルの section 番号およびその section に含まれるページの種類を示します。 1 実行プログラムまたはシェルコマンド 2 システムコール (カーネルが提供する関数) 3 ライブラリー呼び出し (プログラムライブラリーに含まれる関数) 4 Special files (usually found in /dev) 5 File formats and conventions, e.g. /etc/passwd 6 ゲーム 7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) 8 システム管理コマンド (通常は root 用) 9 カーネルルーチン [非標準] マニュアルページ page は複数の節で構成されます。 :
私はセクション1,2,3をよく見ます。セクション1を見ていると、よく使っているコマンドでも知らないオプションについて記述があったり、別の機会に使えそうなオプションの記述があったりと発見があります。
調べたい内容が出力されない場合
例えばですが、printfについて調べようとするとセクション1のprintfコマンドの内容が出力されます。
$ man printf
PRINTF(1) User Commands PRINTF(1) NAME printf - format and print data SYNOPSIS printf FORMAT [ARGUMENT]... printf OPTION DESCRIPTION Print ARGUMENT(s) according to FORMAT, or execute according to OPTION: :
printfコマンドについて調べる場合はこれでよいのですが、printf関数について調べたい場合はライブラリーのセクション3を指定して調べます。
$ man 3 printf
PRINTF(3) Linux Programmer's Manual PRINTF(3) NAME printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf, vdprintf, vsprintf, vsnprintf - formatted output conversion SYNOPSIS #include <stdio.h> int printf(const char *format, ...); int fprintf(FILE *stream, const char *format, ...); int dprintf(int fd, const char *format, ...); int sprintf(char *str, const char *format, ...); int snprintf(char *str, size_t size, const char *format, ...); :
どのセクションにあるかよくわからない場合は-kオプションが助けになると思います。
$ man -k printf Printf (3o) - Formatted output functions. asprintf (3) - print to allocated string dprintf (3) - formatted output conversion fprintf (3) - formatted output conversion fwprintf (3) - formatted wide-character output conversion printf (1) - format and print data printf (3) - formatted output conversion set_matchpathcon_printf (3) - set flags controlling the operation of matchpathcon or matchpathcon_inde... snprintf (3) - formatted output conversion sprintf (3) - formatted output conversion Stdlib.Printf (3o) - no description swprintf (3) - formatted wide-character output conversion vasprintf (3) - print to allocated string vdprintf (3) - formatted output conversion vfprintf (3) - formatted output conversion vfwprintf (3) - formatted wide-character output conversion vprintf (3) - formatted output conversion vsnprintf (3) - formatted output conversion vsprintf (3) - formatted output conversion vswprintf (3) - formatted wide-character output conversion vwprintf (3) - formatted wide-character output conversion wprintf (3) - formatted wide-character output conversion XtAsprintf (3) - memory management functions