Linux基礎知識之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

顯示如下

問題解決。

man的使用需要大家在平時的使用中慢慢摸索這樣才會越用越得心應手。希望大家看了又所幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM