このページで解説している内容は、以下の YouTube 動画の解説で見ることができます。

Linux基礎:マニュアルの使い方

マニュアルの使い方

 Linuxには数千ものコマンドが存在し、それぞれに多様な機能やオプションがあります。すべてのコマンドの使い方を暗記することは困難です。そのためLinuxには「オンラインマニュアル」が整備されており、コマンドの詳細な使い方やオプションの意味を確認できる仕組みが用意されています。

 オンラインマニュアルは manコマンド を使って参照します。また、多くのコマンドには --help オプションもあり、基本的な使い方を簡単に確認することができます。本章では、オンラインマニュアルの利用方法、セクションの仕組み、関連コマンドである whatis、そして --help オプションの活用方法を解説します。

1.manコマンドによるマニュアルの利用

1.1. manコマンドの基本

 Linuxでコマンドの詳細を調べるには man コマンドを使用します。manは「manual」の略で、オンラインマニュアルを表示します。

構文

man [セクション番号] コマンド名
  • セクション番号を省略すると、最初に一致するものが表示されます。
  • 表示内容は複数ページに分かれており、Space キーで次のページ、q キーで終了します。

【例1】cal コマンドのマニュアルを表示

[user@rocky9 ~]$ man cal

【例2】表示例(抜粋)

<pre>CAL(1)                           User Commands                           CAL(1)

<b>NAME</b>
       cal - display a calendar

<b>SYNOPSIS</b>
       <b>cal </b>[options] [[[<u style="text-decoration-style:single">day</u>] <u style="text-decoration-style:single">month</u>] <u style="text-decoration-style:single">year</u>]

       <b>cal </b>[options] [<u style="text-decoration-style:single">timestamp</u>|<u style="text-decoration-style:single">monthname</u>]

<b>DESCRIPTION</b>
       <b>cal </b>displays a simple calendar. If no arguments are specified, the
       current month is displayed.

       The <u style="text-decoration-style:single">month</u> may be specified as a number (1-12), as a month name or as an
       abbreviated month name according to the current locales.

       Two different calendar systems are used, Gregorian and Julian. These are
       nearly identical systems with Gregorian making a small adjustment to the
       frequency of leap years; this facilitates improved synchronization with
       solar events like the equinoxes. The Gregorian calendar reform was
       introduced in 1582, but its adoption continued up to 1923. By default
       <b>cal </b>uses the adoption date of 3 Sept 1752. From that date forward the
       Gregorian calendar is displayed; previous dates use the Julian calendar
       system. 11 days were removed at the time of adoption to bring the
       calendar in sync with solar events. So Sept 1752 has a mix of Julian and
       Gregorian dates by which the 2nd is followed by the 14th (the 3rd
       through the 13th are absent).

ここから、コマンドの構文やオプションの意味を確認できます。

1.2. マニュアルのセクション

 オンラインマニュアルは「セクション」に分かれており、同じ名前でも用途によって複数のマニュアルが存在する場合があります。

セクション番号説明
1一般ユーザー向けコマンド
5設定ファイルの書式
8システム管理コマンド

【例3】passwd コマンド(パスワード変更)のマニュアルを表示

[user@rocky9 ~]$ man passwd

【例4】/etc/passwd ファイル(ユーザー情報ファイル)のマニュアルを表示

[user@rocky9 ~]$ man 5 passwd

→ セクション番号を指定することで「コマンドのマニュアル」と「設定ファイルのマニュアル」を区別できます。

2.関連コマンドと補助機能

2.1. whatisコマンド

どのセクションに該当するのか分からないときは、whatis コマンドを利用します。

構文

whatis コマンド名

【例5】passwd のマニュアル概要を確認

[user@rocky9 ~]$ whatis passwd
passwd (1)           - ユーザパスワードを変更する
passwd (5)           - password file
passwd (1ossl)       - OpenSSL application commands

→ これにより、passwd には「コマンド (1)」と「ファイル (5)」と「OpenSSL の サブコマンド(1ossl)」の3種類があることがわかります。

2.2. --helpオプション

多くのコマンドには --help オプションが用意されており、簡単な使い方を確認できます。

【例6】passwd コマンドのヘルプ表示

[user@rocky9 ~]$ passwd --help
使い方: passwd [オプション...] <accountName>
  -k, --keep-tokens       有効な認証トークンを維持する
  -d, --delete            delete the password for the named account (root only);
                          also removes password lock if any
  -l, --lock              指名されたアカウントのパスワードをロック(rootのみ)
  -u, --unlock            指名されたアカウントのパスワードをロック解除(rootのみ)
  -e, --expire            指名されたアカウントのパスワードを失効(rootのみ)
  -f, --force             操作を強制
  -x, --maximum=DAYS      最大パスワード寿命 (root のみ)
  -n, --minimum=DAYS      最低パスワード寿命 (root のみ)
  -w, --warning=DAYS      パスワード失効の前にユーザーが警告を受ける事前日数 (root のみ)
  -i, --inactive=DAYS     パスワードが失効した後にアカウントが無効になるまでの日数 (root のみ)
  -S, --status            named
                          アカウントのパスワードステータスを報告する (root のみ)
      --stdin             標準入力(stdin)
                          から新規トークンを読み込む (root のみ)

ヘルプオプション:
  -?, --help              このヘルプメッセージを表示します
      --usage             使い方の概要を表示します

manコマンドと比べて簡潔なため、ちょっと確認したいときに便利です。

3.manコマンドでよく確認する項目

マニュアルには多くの情報が含まれていますが、特に以下の項目を押さえると理解が進みます。

項目内容
NAMEコマンドやファイルの名称と概要
SYNOPSIS構文(コマンドの書き方)
DESCRIPTIONコマンドの詳細説明
OPTIONS使用可能なオプションと意味
FILES関連するファイル
SEE ALSO関連するコマンドやマニュアル

4.まとめ

Linuxで効率的に作業を進めるためには、オンラインマニュアルの利用が不可欠です。

  • manコマンド で詳細を確認
  • セクション番号 によりコマンドと設定ファイルを区別
  • whatisコマンド で概要を把握
  • --helpオプション で簡易的に確認

 最初は内容が難しく感じるかもしれませんが、繰り返し使うことで自然と理解が深まります。学習を進める際は、気になるコマンドを実際に man で引いてみる習慣をつけるとよいでしょう。