man手冊的使用

在Linux中man的使用頻率應該是很高的,靈活運用它可以讓自己快速的掌握一個不熟悉命令的使用方法。下面來介紹下man

環境CentOS6.8

man – format and display the on-line manual pages 在線使用手冊格式及展示
通俗點來說它就是命令的使用手冊。
它共分九個章節

1、用戶命令
2、系統調用
3、C庫調用
4、設備文件及特殊文件
5、配置文件格式
6、游戲
7、雜項
8、管理命令及守護進程
9、Linux內核API(CentOS7以后出現)
之所以分這九個章節是應為有的命令分屬不同類,查看命令具體屬于man中的哪個章節需要使用命令
whatis COMMAND

下面就命令echo為例來具體說明man的手冊內容
#whatis echo
echo                 (1)  – display a line of text
echo                 (1p)  – write arguments to standard output
echo [builtins]      (1)  – bash built-in commands, see bash(1)

從上面可以看出來echo屬于man的第一章節
下面從具體的man 1 echo中解釋具體每項的意義
#man 1 echo
NAME     命令名稱及功能簡要說明
       echo – display a line of text
 
SYNOPSIS       用法說明,包括可用的選項
       echo [SHORT-OPTION]… [STRING]…
       echo LONG-OPTION
 
       <>:此符號內為必給內容
       []:此符號內為可選內容
       |:此符號表示多選一
        {}:此符號表示為分組
…:同一內容出現多次
 
DESCRIPTION     命令功能的詳盡說明,可能包括每一項的意義
       Echo the STRING(s) to standard output.
 
       -n     do not output the trailing newline
 
       -e     enable interpretation of backslash escapes
 
       -E     disable interpretation of backslash escapes (default)
 
       –help display this help and exit
 
       –version
              output version information and exit
       .
       .
       .
AUTHOR        作者
       Written by Brian Fox and Chet Ramey.
 
REPORTING BUGS   報告程序bug的方式
       Report echo bugs to bug-coreutils@gnu.org
       GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
       General help using GNU software: <http://www.gnu.org/gethelp/>
       Report echo translation bugs to <http://translationproject.org/team/>
 
COPYRIGHT    版權聲明
       Copyright    2010  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 WARRANTY, to the extent permitted by law.
 
SEE ALSO   另外參照
       The  full documentation for echo is maintained as a Texinfo manual.  If
       the info and echo programs are properly installed  at  your  site,  the
       command
 
              info coreutils 'echo invocation'
 
       should give you access to the complete manual.

有的命令中還有OPTIONS(說明每一個選項的意義)、FILES(此命令相關的配置文件)、ARGUMENTS(命令的作用對象),大致有上面這幾項。

    man命令中的快捷鍵,便于查看文本信息

enter return鍵:向后翻一行         k:向前翻一行

ctrl+d :向文件尾部翻半屏           ctrl+u:向文件首部翻半屏
G:跳至最后一行                     #G:跳轉至指定行,#表示行號

    man查找,用于在man手冊中快速定位需要的信息
/keyword:以keyword指定的字符串為關鍵字,從當前界面所在位置向文件尾部搜索;不區分字符大小寫
n:下一個             N:上一個

?keyword:以keyword指定的字符串為關鍵字,從當前界面所在位置向文件首部搜索;不區分字符大小寫
n:跟收縮命令同方向,下一個      N:跟搜索命令反向,上一個

   當不看man手冊時q為退出

    man的實際應用
下面通過一個實際的問題,來說明man的作用

例子:字符終端登陸時,顯示當前登陸終端號,主機名和當前時間。
要求使用man查找實現上述要求,提示:修改/etc/issue文件。怎么修改可以通過man查看issue求助。
我們先用cat看下/etc/issue文件

# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

之后我們
man issue

Formatting page, please wait…
ISSUE(5)                   Linux Programmer’s Manual                  ISSUE(5)
 
NAME
       issue – pre-login message and identification file
 
DESCRIPTION
       The  file  /etc/issue is a text file which contains a message or system
       identification to be printed before the login prompt.  It  may  contain
       various  @char and \char sequences, if supported by the getty-type pro-
       gram employed on the system.
 
FILES
       /etc/issue
 
SEE ALSO
       motd(5), agetty(8), mingetty(8)
 
COLOPHON
       This page is part of release 3.22 of the Linux  man-pages  project.   A
       description  of  the project, and information about reporting bugs, can
       be found at http://www.kernel.org/doc/man-pages/.
 
Linux                             1993-07-24                          ISSUE(5)

查看之后發現找不到一點有價值的信息,不過在最后提示我們可以查看motd、agetty、mingetty這三個文件。
man motd
MOTD(5)                    Linux Programmer’s Manual                   MOTD(5)
 
NAME
       motd – message of the day
 
DESCRIPTION
       The  contents of /etc/motd are displayed by login(1) after a successful
       login but just before it executes the login shell.
 
       The abbreviation "motd" stands for "message of the day", and this  file
       has  been  traditionally  used  for exactly that (it requires much less
       disk space than mail to all users).
 
FILES
       /etc/motd
 
SEE ALSO
       login(1), issue(5)
 
COLOPHON
       This page is part of release 3.22 of the Linux  man-pages  project.   A
       description  of  the project, and information about reporting bugs, can
       be found at http://www.kernel.org/doc/man-pages/.
 
Linux                             1992-12-29                           MOTD(5)

motd里面也沒有值得我們參考的信息,繼續下一個
man agentty
AGETTY(8)                                                            AGETTY(8)
 
NAME
       agetty – alternative Linux getty
 
SYNOPSIS
       agetty  [-8ihLmnUw]  [-f  issue_file]  [-l login_program] [-I init] [-t
       timeout] [-H login_host] port baud_rate,…  [term]
       agetty [-8ihLmnw] [-f issue_file]  [-l  login_program]  [-I  init]  [-t
       timeout] [-H login_host] baud_rate,…  port [term]
 
DESCRIPTION
       agetty  opens  a  tty  port,  prompts  for a login name and invokes the
       /bin/login command. It is normally invoked by init(8).
 
       agetty has several non-standard features that are useful for hard-wired
       and for dial-in lines:
 
       o      Adapts  the tty settings to parity bits and to erase, kill, end-
              of-line and uppercase characters when it  reads  a  login  name.
              The  program can handle 7-bit characters with even, odd, none or
              space parity, and 8-bit characters with no parity. The following
              special  characters  are  recognized: @ and Control-U (kill); #,
              DEL and back space (erase); carriage return and line  feed  (end
              of line).  See also –erase-chars and –kill-chars options.
 
       o      Optionally  deduces the baud rate from the CONNECT messages pro-
              duced by Hayes(tm)-compatible modems.
              …
              ..
              .

由于這個手冊內容很多,所以我們使用/issue快速找到關于/etc/issue的相關內容作為參考。
connection and turn on auto-answer after 1 ring.)
            /sbin/agetty -w -I ’ATE0Q1&D2&C1S0=1\015’ 115200 ttyS1
 
ISSUE ESCAPES
       The issue-file (/etc/issue or the file set with the -f option) may con-
       tain certain escape codes to display the system  name,  date  and  time
       etc.  All  escape codes consist of a backslash (\) immediately followed
       by one of the letters explained below.
 
       b      Insert the baudrate of the current line.
 
       d      Insert the current date.
 
       s      Insert the system name, the name of the operating system.
 
       l      Insert the name of the current tty line.
 
       m      Insert the architecture identifier of the machine, eg. i486
 
       n      Insert the nodename of the machine, also known as the  hostname.
 
       o      Insert the NIS domainname of the machine.
 
       O      Insert the DNS domainname of the machine.
 
       r      Insert the release number of the OS, eg. 1.1.9.
 
       t      Insert the current time.
 
       u      Insert the number of current users logged in.
 
       U      Insert  the string "1 user" or "<n> users" where <n> is the num-
              ber of current users logged in.
 
       v      Insert the version of the OS, eg. the build-date etc.
 
       Example: On my system, the following /etc/issue file:
 
              This is \n.\o (\s \m \r) \t
 
       displays as
 
              This is thingol.orcan.dk (Linux i386 1.1.9) 18:29:30

這里我們找到\l可以解決顯示當前登陸終端號問題,\n解決主機名問題,\t解決時間顯示問題。既然找到了,那我們嘗試修改/etc/issue文件。
#vi /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m
\l         
\n
time is \t

wq保存退出。
logout

結果如下:

image.png

原創文章,作者:21期王逸凡,如若轉載,請注明出處:http://www.www58058.com/52276

(1)
21期王逸凡21期王逸凡
上一篇 2016-10-19 14:17
下一篇 2016-10-19 14:19

相關推薦

  • 第二周 N28

    作業二

    2017-12-10
  • grep、egrep、vim練習

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及內部文件的屬組和其它用戶均沒有任何訪問權限。         [root@localhost ~]# install -d -m 600&nb…

    Linux干貨 2016-11-18
  • 馬哥教育-第一周作業

    第一部分:計算機組成及功能 電子真空管的出現促使了計算機的誕生; 根據馮●諾依曼的哲學思想,計算機的組成分為五大部分。分別為: 1.     運算器 2.     控制器 3.     存儲器 4.   &nb…

    Linux干貨 2016-12-04
  • 文本處理三劍客-grep及正則表達式初

    什么是正則表達式 基本正則表達式的元字符 擴展正則表達式 grep的基本理解 grep的基本選項 grep的應用實例 什么是正則表達式   正則表達式,又稱正規表示法、常規表示法。(英語:Regular Expression,在代碼中常簡寫為regex、regexp或RE),計算機科學的一個概念。正則表通常被用來檢索、替換那些符合某個模式的文本。(…

    Linux干貨 2016-08-07
  • 文本處理工具

    1、cat命令 功能: 顯示文本內容,連接合并文本內容并在標準設備上輸出 語法: cat [OPTION]… [FILE]… 選項: -E:顯示行結束符(回車)$ -A:顯示所有控制符,相當于-vET -n:對顯示出的每一行進行編號 -b:對非空白行編號 -s:將連續的空行壓縮成一行 -T:把TAB字符顯示為^I -v:除了&nb…

    Linux干貨 2016-08-07
  • ansible

    運維自動化發展歷程,ansible 命令使用

    2018-01-13
欧美性久久久久