man ページ/ナビゲーション

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Man page/Navigate and the translation is 53% complete.

このガイドでは、man コマンドを用いた man ページの閲覧方法について紹介します。

はじめに

manプログラム

Linux の経験の中で誰もが一度は man コマンドを使ったことがあることでしょう。しかし、man プログラム自体はどちらかと言うとシンプルな構成のように思える一方、単にページをスクロールするだけではない、いくつかの機能が備わっています。このドキュメントが、そうした機能に光を当てる助けとなっていれば幸いです。

Manレイアウト

man ページは主に /usr/share/man ディレクトリに保管されます。しかし、MANPATH 環境変数の場所に置かれてさえいれば、man はその man ページを見つけることができます。Gentoo は通常、MANPATH 変数を /etc/env.d で設定します。これらのディレクトリの中に、manX (ここで X はセクション番号です) という構造のフォルダがいくつかあります。例えば、標準の man のレイアウトは以下のようになっているかもしれません:

user $ls /usr/share/man | grep man
man0p
man1
man1p
man2
man3
man3p
man4
man5
man6
man7
man8
man9
mann

実際のセクション番号の付け方は、まあまあ標準化されているように見えます。しかし、mann フォルダと、いくつかの man#p フォルダもあることに気づくでしょう。次の表に、上の man ページディレクトリと、そこに何が含まれているかの一覧を示します:

Man ディレクトリ 説明
man0p ここでの "p" は POSIX の略で、名前に p が含まれる他のディレクトリも同様です。このディレクトリ内の man ページはさまざまな POSIX ヘッダファイルの機能について記述しています。
man1 このセクションは標準的なコマンドのためのものです。ほとんどのプログラムは自身の man ページをここに置くことになるので、このセクションが最大になる傾向にあります。
man1p このセクションは 1p で記述されたコマンドの POSIX 版です。基本的なコマンドのみを記述しているので、man1 よりもずっと小さいです。
man2 このセクションは Linux カーネルシステムコールを記述します。
man3 このセクションは C 言語標準ライブラリ関数を記述します。
man4 このセクションはスペシャルデバイスを記述します。これらのデバイスは通常はカーネルに関連するものですが、Xorg-X11 もこの中にエントリを持っています。
man5 このセクションは、特定のファイルの構造と、プログラムがどのファイルを使用するかを記述します。このドキュメントを読んでいる方の中には、Portage のファイル構造の記述を見るための man 5 portage コマンドへの言及や、make.conf の構造のための man 5 make.conf コマンドで馴染み深いという人もいるでしょう。
man6 このセクションはゲームやその他特別な遊び道具を紹介します。
man7 このセクションは標準とその他の雑多な項目を記述します。これらの標準は、文字集合、SQL 文、ISO 標準、正規表現を含みます。
man8 このセクションは管理コマンド (通常は root ユーザによって実行されるコマンド) を記述します。
man9 このセクションはいくぶん存在感が薄いですが、カーネルの様々なパーツのドキュメントを格納することが意図されています。
mann このセクションは主に dev-lang/tcl または dev-lang/tk によって使用されます。"n" は new の略です。

これは完全で詳細な一覧ではありませんが、多くの人々が興味を持つであろう man ページをの範囲を網羅できているでしょう。しかしながら、各セクションが何を扱うのかは、この表を見るのと同じくらい簡単に分かるかもしれません。次のチャプターでは、このレイアウトを横断するために man を使う方法について見ていきましょう。

Working with the man layout

man のレイアウトから情報を探す

man のレイアウトについて理解できたら、コマンドの man ページを眺めてみることにしましょう。場合によっては、読みたい man ページを絞り込む必要があるかもしれません。最初の方法はセクションによって指定する方法です。セクションについての説明を探すには、次のように man <section> intro を利用することができます:

user $man 3 intro
## (出力は文書に適切に合わせるために多少異なることがあります)
INTRO(3)               Linux Programmer's Manual                INTRO(3)
 
 
 
NAME
       intro - Introduction to library functions
 
DESCRIPTION
       This chapter describes all library functions excluding the library
       functions described in chapter 2, which implement system calls.
       There are various function groups which can be identified by a
       letter which is appended to the chapter number:
....

残念ながら、この方法がいつもうまく行くとは限りません。しかしながら幸運にも、複数の結果を返すことがあるコマンド (ライブラリ呼び出しとシステムコマンドが同じ名前を持っている場合など) の中から検索するための方法は、他にもあります。次のように man コマンドの -K を使用してください:

user $man -K sleep
/usr/share/man/man0p/time.h.0p.gz? [ynq] n
/usr/share/man/man0p/unistd.h.0p.gz? [ynq] n
/usr/share/man/man2/alarm.2.gz? [ynq] n
/usr/share/man/man2/pause.2.gz? [ynq] n
/usr/share/man/man2/futex.2.gz? [ynq] n
/usr/share/man/man2/nanosleep.2.gz? [ynq] y
/usr/share/man/man2/semop.2.gz? [ynq] q

出力はもっと長くなることもあります。その場合は、もっと絞り込めるキーワードを指定したほうがいいかもしれません。man ページがどこにあるか探す方法が分かったら、次の節では man ページの閲覧について見ていきましょう。

man ページを閲覧する

Viewing man pages can be done in 2 ways, first is with man [man page name]. The second way is man <section> [man page name]. Take sys-devel/bc for example. I can view either the first man page that comes up on bc (which would be section 1, because it is the lowest section containing a man page on bc):

user $man bc
bc(1)                                            bc(1)
 
 
NAME
       bc - An arbitrary precision calculator language
...

However, what if I want the POSIX version? Then I can use the second form:

user $man 1p bc
BC(P)        POSIX Programmer's Manual           BC(P)
 
 
NAME
       bc - arbitrary-precision arithmetic language
...

And the man page is displayed. Now that we have the man page up, it is time to work with it. The next section will look at navigation and searching.

man ページ内を移動し、検索する

Navigating a man page is fairly simple. To move up and down line by line, use the and arrow keys. To move up page by page, you can use the Page up and Page down keys. Do however note that these navigation instructions assume the environmental PAGER variable is set to use the default pager, less. Less also has a few other commands for navigation, but the arrow keys usually suffice:

コード Additional less navigation keys
  e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
  y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
  f  ^F  ^V  SPACE  *  Forward  one window (or N lines).
  b  ^B  ESC-v      *  Backward one window (or N lines).
  z                 *  Forward  one window (and set window to N).
  w                 *  Backward one window (and set window to N).
  ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
  d  ^D             *  Forward  one half-window (and set half-window to N).
  u  ^U             *  Backward one half-window (and set half-window to N).
  ESC-)  RightArrow *  Shift view right  one half screen width (or N positions).
  ESC-(  LeftArrow  *  Shift view left one half screen width (or N positions).
  F                    Forward forever; like "tail -f".

Searching, however, is more interesting. The two most basic searches are /pattern and ?pattern. The first version searches forwards, and the second searches backwards. pattern is a regular expression pattern that is described in man 7 regex. Let's take for example searching for the -D option to emerge. First, bring up the emerge man page:

user $man emerge

Then, at the screen, press the / key to bring up the entry prompt to search forwards and enter in our search pattern:

コード Bringing up the forward search prompt
gracefully handles updating installed packages to newer releases as well.
     It handles both source and binary packages, and it can be used to create
     binary packages for distribution.
 
EBUILDS, TBZ2S, CLASSES AND DEPENDENCIES
/\-D
メモ
The \ is done to escape the - sign, which would normally be used as part of a regular expression.

This will search the man page, and bring the searched item into focus:

コード Forward search results
--deep (-D)
        When used in conjunction with --update, this flag forces emerge to consider the entire
        dependency tree of packages, instead of checking only the immediate dependencies of
        the packages.  As an example, this catches updates in libraries that are not directly
        listed in the  dependencies of a package.

If you hit a search result by accident and want to continue searching for the same results, simply press the / key again, and press Enter (i.e. don't put a pattern it). This will cause the search to default to the last pattern used. Now with some man pages, options are listed, then explained later on. Take the man 5 portage man page. It lists the files used, then explains their usage. Searching forward a few times would return the results, but there's an easier way to handle this, with the second search form, backwards searching. Let's use this to find the description on package.unmask. First, bring up man 5 portage:

user $man 5 portage

Now press Shift+g. This will bring you to the end of the page:

コード End of the man page after SHIFT+g
SEE ALSO
       emerge(1), ebuild(1), ebuild(5), make.conf(5)
 
Portage 2.0.51        Jan 2004            PORTAGE(5)
lines 418-442/442 (END)

Now we'll go ahead and enter the pattern to search for with the ?pattern backwards search option. First press the ? key to bring up the prompt, and then enter in package.unmask, our query:

コード Specifying our search
SEE ALSO
       emerge(1), ebuild(1), ebuild(5), make.conf(5)
 
Portage 2.0.51        Jan 2004           PORTAGE(5)
?package.unmask

Then hit Enter to bring up the result:

コード Our search result
package.unmask
       Just like package.mask above, except here you list packages you want to unmask.
       Useful for overriding the global  package.mask  file (see below).  Note that
       this does not override packages that are masked via KEYWORDS.
...

And the search is complete! Note that just as with /, using ? search with no pattern will use the last pattern to search.

Conclusion

This concludes the man guide. This will hopefully shed some light on navigating man pages, and maybe even give a few new tips to the more experienced users. For those who prefer alternate means of navigating man pages, the following are also available:

KDE web ブラウザの kde-apps/konqueror も、アドレスバー内で man: 構文を使用することで、man ページを閲覧することができます。


This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Chris White
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.