2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

意外と知らないwhatisコマンド!

whatisもしくは、aproposコマンドはキーワード(コマンド名等)で指定するとwhatisデータベースで検索して、そのキーワードの簡単な説明を出力する。まあ言ってみればmanの概要のところを抜き出して一行ヘルプみたいに説明してくれる便利なコマンドである。しかし、こいつちゃんとwhatisDBを作ってやらないと駄目な野郎です。


例えばchmodコマンドで検索すると、

# whatis chmod
chmod (1) – change file access permissions
chmod (2) – change permissions of a file

こんなんでる。

新しいコマンドが増えてDBをリニューする場合は、

# makewhatis -u -v -w
about to enter /usr/kerberos/man
about to enter /usr/share/man/ja
about to enter /usr/share/man

これで新しいDBを作る。みなさん知っているか解らないけど、Linuxではこれは九龍で定期的にやってくれてる。
例えば、RedHat系Linuxであるが、

# ls -al
total 28
drwxr-xr-x 2 root root 4096 Sep 12 2003 .
drwxr-xr-x 41 root root 4096 Nov 23 13:52 ..
-rwxr-xr-x 1 root root 276 Sep 12 2001 0anacron
-rwxr-xr-x 1 root root 51 Sep 12 2001 logrotate
-rw-r—– 1 root root 34 Oct 30 2002 logrotate-after
-rwxr-xr-x 1 root root 402 Sep 12 2001 makewhatis.cron
-rwxr-xr-x 1 root root 121 Sep 13 2001 slocate.cron

の中でmakewhatis.cronがそうである。
証拠に中身を覗いてみよう。

# more makewhatis.cron

#!/bin/bash

LOCKFILE=/var/lock/makewhatis.lock

# the lockfile is not meant to be perfect, it’s just in case the
# two makewhatis cron scripts get run close to each other to keep
# them from stepping on each other’s toes. The worst that will
# happen is that they will temporarily corrupt the database…
[ -f $LOCKFILE ] && exit 0
trap “rm -f $LOCKFILE” EXIT
touch $LOCKFILE
makewhatis -u -w
exit 0

こんな感じのシェルになってる。だから、知らないうちにDBを作ってくれちゃってると言うことだ。 ご存じだっただろうか。

以上

コメント