Linux求助命令man page

1.指令--help求助说明

  事實上,幾乎 Linux 上面的指令,在開發的時候,開發者就將可以使用的指令語法與參數寫入指令操作過程中了!你只要使用『 --help 』這個選項, 就能夠將該指令的用法作一個大致的理解喔!舉例來說,我們來瞧瞧 date 這個指令的基本用法與選項參數的介紹:

[dmtsai@study ~]# date --help
Usage: date [OPTION]... [+FORMAT]                           # 基本语法
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]  # 设定时间的语法
Display the current time in the given FORMAT, or set the system date.
# 底下是主要的選項說明
Mandatory arguments to long options are mandatory for short options too.
  -d, --date=STRING         display time described by STRING, not 'now'
  -f, --file=DATEFILE       like --date once for each line of DATEFILE
....(中間省略)....
  -u, --utc, --universal    print or set Coordinated Universal Time (UTC)
      --help     顯示此求助說明並離開
      --version  顯示版本資訊並離開
# 底下則是重要的格式 (FORMAT) 的主要項目
FORMAT controls the output.  Interpreted sequences are:

  %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
....(中間省略)....
# 底下是幾個重要的範例 (Example)
Examples:
Convert seconds since the epoch (1970-01-01 UTC) to a date
  $ date --date='@2147483647'
....(底下省略)....

usage:使用方法。

option:选项对应下方的 -“X”对应各种功能

format:对应下方 FORMAT controls the output。

Examples:举例。

2.man page

相对于比--help 更加详细清楚的说明

[dmtsai@study ~]$ LANG="en_US.utf8"
[dmtsai@study ~]$ man date
DATE(1)                          User Commands                         DATE(1)
# 請注意上面這個括號內的數字
NAME  <==這個指令的完整全名,如下所示為date且說明簡單用途為設定與顯示日期/時間
       date - print or set the system date and time

SYNOPSIS  <==这个指令的基本用法如下所示
       date [OPTION]... [+FORMAT]                            <==第一种单纯显示的用法
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]   <==这种可以设定系统时间的用法

DESCRIPTION  <==详细说明刚刚语法谈到的选项与参数的用法
       Display the current time in the given FORMAT, or set the system date.

       Mandatory arguments to long options are mandatory for short options too.

       -d, --date=STRING  <==左边是短选项名臣,右边是完整选项名称
              display time described by STRING, not 'now'

       -f, --file=DATEFILE
              like --date once for each line of DATEFILE

       -I[TIMESPEC], --iso-8601[=TIMESPEC]
              output  date/time  in  ISO  8601  format.   TIMESPEC='date' for date only (the
              default), 'hours', 'minutes', 'seconds', or 'ns' for  date  and  time  to  the
              indicated precision.
....(中間省略)....
       # 找到了!底下就是格式化輸出的詳細資料!
       FORMAT controls the output.  Interpreted sequences are:

       %%     a literal %

       %a     locale's abbreviated weekday name (e.g., Sun)

       %A     locale's full weekday name (e.g., Sunday)
....(中間省略)....
ENVIRONMENT  <==与这个指令相关的环境参数有如下说明
       TZ     Specifies the timezone, unless overridden by command line parameters.  
              If neither is specified, the setting from /etc/localtime is used.

EXAMPLES     <==可用的范本
       Convert seconds since the epoch (1970-01-01 UTC) to a date

              $ date --date='@2147483647'
....(中間省略)....

DATE STRING  <==上面曾提到的 --date 的格式說明!
       The --date=STRING is a mostly free format human readable date string such as "Sun, 29
       Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next  Thursday".   A  date
       string  may  contain  items  indicating calendar date, time of day, time zone, day of

AUTHOR  <==這個指令的作者啦!
       Written by David MacKenzie.

COPYRIGHT  <==受到著作權法的保護!用的就是 GPL 了!
       Copyright © 2013 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or
       later <http://gnu.org/licenses/gpl.html>.
       This  is free software: you are free to change and redistribute it.  There is NO WAR‐
       RANTY, to the extent permitted by law.

SEE ALSO  <==這個重要,你還可以從哪裡查到與date相關的說明文件之意
       The full documentation for date is maintained as a Texinfo manual.  If the  info  and
       date programs are properly installed at your site, the command

              info coreutils 'date invocation'

       should give you access to the complete manual.

GNU coreutils 8.22                        June 2014                                  DATE(1)

Tips

進入man指令的功能後,你可以按下『空白鍵』往下翻頁,可以按下『 q 』按鍵來離開man的環境。 更多在man指令下的功能,本小節後面會談到的!

                                                                                                                                                                                                                                                                                     鳥哥的圖示

 

在上個表格的第一行,你可以看到的是:『DATE(1)』,DATE我們知道是指令的名稱, 那麼(1)代表什麼呢?他代表的是『一般使用者可使用的指令』的意思!咦!還有這個用意啊!呵呵! 沒錯~在查詢資料的後面的數字是有意義的喔!他可以帮助我们了解或者是直接查询相关的資料。 常見的幾個數字的意義是這樣的:

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

 

 再來,man page的內容也分成好幾個部分來加以介紹該指令呢!就是上頭man date那個表格內, 以NAME作為開始介紹,最後還有個SEE ALSO來作為結束。基本上,man page大致分成底下這幾個部分:

名称 内容说明
NAME

简短的指令资料名称说明

SYNOPSIS 簡短的指令下達語法(syntax)簡介
DESCRIPTION 較為完整的說明,這部分最好仔細看看!
OPTIONS 針對 SYNOPSIS 部分中,有列舉的所有可用的選項說明
COMMANDS 當這個程式(軟體)在執行的時候,可以在此程式(軟體)中下達的指令
FILES 這個程式或資料所使用或參考或連結到的某些檔案
SEE ALSO 可以參考的,跟這個指令或資料有相關的其他說明!
EXAMPLE 一些可以參考的範例
  1. 先察看NAME的項目,約略看一下這個資料的意思;
  2. 再詳看一下DESCRIPTION,這個部分會提到很多相關的資料與使用時機,從這個地方可以學到很多小細節呢;
  3. 而如果這個指令其實很熟悉了(例如上面的date),那麼鳥哥主要就是查詢關於OPTIONS的部分了! 可以知道每個選項的意義,這樣就可以下達比較細部的指令內容呢!
  4. 最後,再看一下,跟這個資料有關的還有哪些東西可以使用的?舉例來說,上面的SEE ALSO就告知我們還可以利用『info coreutils date』來進一步查閱資料;
  5. 某些說明內容還會列舉有關的檔案(FILES 部分)來提供我們參考!這些都是很有幫助的!

 

大致上瞭解了man page的內容後,那麼在man page當中我還可以利用哪些按鍵來幫忙查閱呢?首先, 如果要向下翻頁的話,可以按下鍵盤的空白鍵,也可以使用[Page Up]與[Page Down]來翻頁呢!同時,如果你知道某些關鍵字的話, 那麼可以在任何時候輸入『/word』,來主動搜尋關鍵字!

 

 

2017-10-13

posted @ 2017-10-13 20:48  沈俊杰  阅读(253)  评论(0)    收藏  举报