1

CentOS 6.7, Ubuntu 15.04 のそれぞれで以下のコマンドを実行すると、manページ(セクション1のみ)の概要一覧を意図通りに表示できます。

(Ubuntu での実行例: manpage-jaをインストールしているのでところどころ日本語で表示されています)

$ for filename in /usr/share/man/man1/*.1.gz; do cmd=`basename $filename .1.gz`; man -f $cmd; done
2to3-2.7 (1)         - Python2 to Python3 converter
2to3-3.4 (1)         - Python2 to Python3 converter
2to3 (1)             - Python2 to Python3 converter
411toppm (1)         - convert Sony Mavica .411 image to ppm
Mail (1)             - send and receive Internet mail
...
zless (1)            - 圧縮されたテキストを CRT で見るためのファイル閲覧フィルタ
zlib-flate (1)       - raw zlib compression program
zmore (1)            - 圧縮されたテキストを CRT で見るためのファイル閲覧フィルタ
znew (1)             - .Z ファイルを再圧縮して .gz ファイルにする
zsoelim (1)          - satisfy .so requests in roff input

これがfreeBSD-10.2-stableで実行した場合、全く想定外の挙動をしました。

$ for filename in /usr/share/man/man1/*.1.gz; do cmd=`basename $filename .1.gz`; man -f ${cmd:-}; done
c2ph(1), pstruct(1)      - Dump C structures as generated from "cc -g -S" stabs
biff(1)                  - be notified if mail arrives and who it is from
ctm_smail(1), ctm_dequeue(1), ctm_rmail(1) - send and receive ctm(1) deltas via mail
forward(5)               - mail forwarding instructions
from(1)                  - print names of those who have sent mail
...
...
[: nothing appropriate
...
...
tblgen(1)                - Target Description To C++ Code Generator rst2man-indent-level 0 1 rstReportMargin \$1 
[an-margin] level 
[rst2man-indent-level] level margin: 
[rst2man-indent
[rst2man-indent-level]] - 
[rst2man-indent0] 
[rst2man-indent1] 
[rst2man-indent2] . 1 INDENT RS \$1 nr rst2man-indent
[rst2man-indent-level] 
[an-margin] nr rst2man-indent-level +1 . UNINDENT RE rst2man-indent-level -1 
[rst2man-indent
[rst2man-indent-level]]u
tcsh(1)                  - C shell with file name completion and command line editing
xstr(1)                  - extract strings from C programs to implement shared strings
DynaLoader(3)            - Dynamically load C libraries into Perl code
ExtUtils::CBuilder(3)    - Compile and link C code for Perl modules
ExtUtils::Constant(3)    - generate XS code to import C header constants
ExtUtils::Constant::XS(3) - generate C code for XS modules' constants
ExtUtils::Embed(3)       - Utilities for embedding Perl in C/C++ applications
ExtUtils::Miniperl(3)    - write the C code for perlmain.c
ExtUtils::ParseXS(3)     - converts Perl XS code into C code
Fcntl(3)                 - load the C Fcntl.h defines
List::Util::XS(3)        - Indicate if List::Util was compiled with a C compiler
XSLoader(3)              - Dynamically load C libraries into Perl code
c2ph(1), pstruct(1)      - Dump C structures as generated from "cc -g -S" stabs
--More-- (byte 2220)

man -f としているだけなのにどういうわけか途中でページャ(more)によるユーザー入力待ち状態になってしまいます。

確かに FreeBSD のmanを見るとman -fwhatis(1)コマンドを実行し、そのwhatisは環境変数PAGERの影響を受けると書かれていました。ページャデフォルトがmoreであるとも。

しかしman -f を単体で動作したときにはページャ表示に切り替わってユーザー入力待ちとなるような動作は確認できませんでした。

$ man -f c2ph
c2ph(1), pstruct(1)      - Dump C structures as generated from "cc -g -S" stabs

コマンドの仕様について分かってないとか、実行コマンドの書き方に問題があるとか、そういうことだろうと思って調べてみたものの理解が及びません。ご教示お願いいたします。

2 件の回答 2

1
$ for filename in /usr/share/man/man1/*.1.gz; do cmd=`basename $filename .1.gz`; man -f $cmd | cat; done

するか、

$ for filename in /usr/share/man/man1/*.1.gz; do cmd=`basename $filename .1.gz`; PAGER=cat man -f $cmd; done

でいけませんか?

$ man -f perl

とかするとなんとなく感じがつかめるかも。

2
  • 両方ともいけました。なぜこういう挙動になってしまうのか理由はわかってませんが……
    – cul8er
    2015年11月23日 20:20
  • 1
    FreeBSDとLinuxではwhatisコマンドに若干の違いがあります。@argus さんの言うとおりで、FreeBSDだとkeywordでgrepするのでwhatisの結果が複数のページに渡るほど表示される場合があります。(PAGERがデフォルトがmoreなので、複数のページになった時だけユーザの入力を待つようになります)
    – ernix
    2015年11月24日 6:12
1

本題とは関係がないのですが、

manページ(セクション1のみ)の概要一覧を意図通りに表示できます。

Ubuntu Linux の whatis コマンドでは指定したセクションに属するコマンドの概要を表示するオプションスイッチがあります。

whatis(1)

 -s list, --sections list, --section list
  Search only the given manual sections. list is a colon- or comma-separated list of sections.

 -w, --wildcard
  Interpret each name as a pattern containing shell style wildcards.

 -r, --regex
  Interpret each name as a regular expression.

例えば、Section 1 のみの概要を表示する場合は以下のようにします。

$ whatis -s 1 -w '*'
or
$ whatis -s 1 -r '.*'

一方、FreeBSD の whatis にはこの様なオプションはありませんが、

whatis(1)

 The keyword is simply passed to grep(1) allowing for extended regular expression matches.

となっていますので、例えば、

# Section 1
$ whatis '^[^(]+\(1\)'

# Section 1 or 3
$ whatis '^[^(]+\([13]\)'

などとする事によってセクションをある程度は絞り込む事ができます。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。