1. 程式人生 > >Linux-man & info

Linux-man & info

man page & info page


man page 的使用

man是manual(操作說明)的簡寫。

macdeMacBook-Air:~ mac$ man
What manual page do you want?

以date命令為例

DATE(1)                   BSD General Commands Manual                  DATE(1)

NAME
     date -- display or set date and time

SYNOPSIS
     date [-jRu] [-r seconds | filename] [-v [+|-]val[ymwdHMS]] ...
          [+output_fmt]
     date
[-jnu] [[[mm]dd]HH]MM[[cc]yy][.ss] date [-jnRu] -f input_fmt new_date [+output_fmt] date [-d dst] [-t minutes_west] DESCRIPTION When invoked without arguments, the date utility displays the current date and time. Otherwise, depending on the options specified, date will set
the date and time or print it in a user-defined way. The date utility displays the date and time read from the kernel clock. When used to set the date and time, both the kernel clock and the hard- ware clock are updated. ---中間省略--- ENVIRONMENT The following environment variables affect the
execution of date: TZ The timezone to use when displaying dates. The normal format is a pathname relative to /usr/share/zoneinfo. For example, the command ``TZ=America/Los_Angeles date'' displays the current time in California. See environ(7) for more information. FILES /var/log/messages record of the user setting the time EXIT STATUS The date utility exits 0 on success, 1 if unable to set the date, and 2 if able to set the local date, but unable to set it globally. EXAMPLES The command: ---中間省略--- DIAGNOSTICS Occasionally, when timed(8) synchronizes the time on many hosts, the set- ting of a new time value may require more than a few seconds. On these occasions, date prints: `Network time being set'. The message `Communication error with timed' occurs when the communication between date and timed(8) fails. LEGACY SYNOPSIS As above, except for the second line, which is: date [-jnu] [[[[[cc]yy]mm]dd]HH]MM[.ss] LEGACY DIAGNOSTICS When invoked in legacy mode, the following exit values are returned: 0 The date was written successfully 1 Unable to set the date 2 Able to set the local date, but unable to set it globally For more information about legacy mode, see compat(5). SEE ALSO locale(1), gettimeofday(2), getutxent(3), strftime(3), strptime(3),timed(8) R. Gusella and S. Zatti, TSP: The Time Synchronization Protocol for UNIX 4.3BSD. STANDARDS The date utility is expected to be compatible with IEEE Std 1003.2 (``POSIX.2''). The -d, -f, -j, -n, -r, -t, and -v options are all exten- sions to the standard. HISTORY A date command appeared in Version 1 AT&T UNIX. BSD May 7, 2015 BSD (END)

進入man命令的功能後,你可以按下空格鍵往下翻頁,可以按下“q”按鍵來離開man的環境。


  1. 注意-man date命令 首先出現的DETE(1) 中(1)的意思

    (1)代表的是一般使用者可使用的命令。在查詢資料的後面的數字是有意義的。它可以幫助我們瞭解或者是直接查詢相關的資料。常見的幾個數字的意義如下表。

    代號 代表內容
    1 使用者在shell環境中可以操作的命令或可執行檔案
    2 系統核心課呼叫的函式與工具等
    3 一些常用的函式(function)與函式庫(library),大部分為C的函式庫(libc)
    4 裝置檔案的說明,通常在/dev 下的檔案
    5 配置檔案或者是某些檔案的格式
    6 遊戲(games)
    7 慣例與協議等,例如Linux檔案系統、網路協議、ASCll code等說明
    8 系統管理員可用的管理命令
    9 跟kernel有關的檔案

2.man page內容主要劃分為下面這幾個主要部分

man page的內容也分成好幾個部分來加以介紹。前面的man page中,以NAME作為開始介紹,最後有個 SEE ALSO來作為結束。基本上,man page大致分為下面幾個部分。

代號 內容說明
NAME 簡短的命令、資料名稱說明
SYNOPSIS 簡短的命令執行語法(syntax)簡介
DESCRIPTION 較為完整的說明,這部分需要仔細看看
OPTIONS 針對SYNOPSIS部分中,有列舉的所有可用的選項說明
COMMANDS 當這個程式(軟體)在執行的時候,可以在此程式(軟體)中執行的命令
FILES 這個程式或資料所使用或參考或連線到的某些檔案
SEE ALSO 這個命令或資料有關的其他說明
EXAMPLE 一些可以參考的範例
BUGS 是否有相關的錯誤

3.在man page 中常用的按鍵

按鍵 進行工作
空格鍵 向下翻一頁
[Page Down]—— 向下翻一頁
[Page Up] 向上翻一頁
[Home] 去到第一頁
[End] 去到最後一頁
/string 向下查詢string字串,如果要查詢cpyh的話,就輸入/cpyh
?string 向上查詢string字串
n,N 利用/或?來查詢字串時,可以使用n來繼續下一個查詢(不論是/或?),可以利用N來進行反向查詢。
q 結束這次的man page

上面的按鍵必須在man page的介面當中才能使用。

4.查詢特定命令/檔案的man page說明檔案

在某些情況下,我們可能知道要使用某些特定的命令或者是修改某些特定的配置檔案,但是忘記來該命令的完整名稱。有些時候則是隻記得該命令的部分關鍵字。這個時候如何查找出來想要知道的man page呢?

-f引數:用於查詢系統中所有跟(命令)有關的說明檔案(以man為例)

macdeMacBook-Air:~ mac$ man -f man
IO::Socket::SSL::Intercept(3pm) - -- SSL interception (man in the middle)
Pod::Man(3pm)            - Convert POD data to formatted *roff input
Pod::Perldoc::ToMan(3pm) - let Perldoc render Pod as man pages
groff_man(7)             - groff `man' macros to support generation of man pages
groffer(1)               - display groff files and man~pages on X and tty
man(1)                   - format and display the on-line manual pages
man.conf(5)              - configuration data for man
zshall(1)                - the Z shell meta-man page

-k引數:在系統的說明檔案中,只要有(命令)這個關鍵字就將該說明列出來

APR::Brigade(3pm)        - Perl API for manipulating APR Bucket Brigades
APR::Bucket(3pm)         - Perl API for manipulating APR Buckets
APR::Date(3pm)           - Perl API for APR date manipulating functions
APR::String(3pm)         - Perl API for manipulating APR UUIDs
APR::Table(3pm)          - Perl API for manipulating APR opaque 
git-reflog(1)            - Manage reflog information
git-remote(1)            - Manage set of tracked repositories
git-remote-ext(1)        - Bridge smart transport to external command
git-worktree(1)          - Manage multiple working trees
---省略---

5.其他與man page相關

whatis[命令或者是資料]<==相當於man -f [命令或者是資料]
apropos[命令或者是資料]<==相當於man -k [命令或者是資料]
注意:這兩個特殊命令使用的前提是建立 whatis 資料庫才行。這個資料庫的建立需要以root的身份執行如下命令

sh-3.2# makewhatis


info page的使用

與man page的主要區別
man page一下子輸出一堆資訊,info page則是將檔案資料拆分成一個一個的段落,每個段落用自己的頁面來撰寫,並且在各個頁面中還有類似網頁的“超連結”來跳到各不同的頁面中,每個獨立的頁面也被稱為一個節點(node)。

File: info.info,  Node: Top,  Next: Getting Started,  Up: (dir)

Info: An Introduction
*********************

The GNU Project distributes most of its on-line manuals in the "Info
format", which you read using an "Info reader".  You are probably using
an Info reader to read this now.

   There are two primary Info readers: `info', a stand-alone program
designed just to read Info files, and the `info' package in GNU Emacs,
a general-purpose editor.  At present, only the Emacs reader supports
using a mouse.

   If you are new to the Info reader and want to learn how to use it,
type the command `h' now.  It brings you to a programmed instruction
sequence.

   To read about expert-level Info commands, type `n' twice.  This
brings you to `Info for Experts', skipping over the `Getting Started'
chapter.

-----Info:(info.info)Top,29 行 --Top---------------------------------------
歡迎使用 Info 4.8 版。輸入 ? 以獲得幫助,m 將得到選單。

·File:代表這個info page的資料是來自info.info檔案提供的。

·Node:代表目前的這個頁面是屬於Top節點。意思是info.info內含有很多資訊,而Top僅是info.info檔案內的一個節點內容而已。

·Next:下一個節點的名稱為Getting Started,你也可以按“N”到下個節點去。

·Up:回到上一層的節點總攬介面,也可以按下“U”回到上一層。

·Prev:前一個節點。這裡已經是第一個節點,所以沒有上一個節點。

info的說明檔案將內容分成多個節點,並且每個節點都有定位與連結。在各連結之間還可以具有類似“超連結”的快速按鈕,可以通過[Tab]鍵在各個超連結間移動,也可以使用U、P、N鍵來在各個階層與相關連結中顯示。
附info page當中可以使用的按鍵及功用。

按鍵 進行工作
空格鍵 向下翻一頁
[Page Down] 向下翻一頁
[Page Up] 向上翻一頁
[Tab] 在節點之間移動,有節點的地方,通常會以“*”顯示
[Enter] 當游標在節點上面時,按下[Enter]可以進入該節點
B 移動游標到該info介面當中的第一個節點處
E 移動游標到該info介面當中的最後一個節點處
N 前往下一個節點處
P 前往上一個節點處
U 向上移動一層
S(/) 在info page當中進行查詢
H 顯示求助選單
命令一覽表
Q 結束這次的info page

info page必須用info page的格式來寫成線上求助檔案。如果一個命令不是以info page格式寫成的說明檔案,那麼使用info命令與man命令得到的結果相同。


其他有用的檔案(documents)?

線上幫助檔案只是很少的一部分,還有相當多的說明需要額外的檔案。這些檔案以TXT、HTML、PDF等格式儲存在/usr/share/doc目錄中。


快捷使用
幾乎所有命令都可以使用-h或–help引數獲取使用方法,引數資訊等。


*本文參閱圖書:鳥哥的Linux私房菜(基礎學習篇(第三版))*
       *示例為在mac air上的終端顯示結果*