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
下一篇 2016-10-19

相關推薦

  • Cent OS 6 編譯方式安裝LAMP

    細節要求: (1) 三者分離于三臺主機; (2) 一個虛擬主機用于提供phpMyAdmin;另一個虛擬主機用于提供wordpress; (3) PHP使用FastCGI+xcache; (4) httpd使用非prefork的mpm模式; 一、CentOS6環境準備 1、OS(CentOS6.8)下開發環境包的安裝,編譯安裝程序包需要使用 #yum grou…

    Linux干貨 2017-02-24
  • yum使用和源碼編譯進程

    yum 是通過分析RPM的標頭數據,根據各軟件的依賴關系制作出有依賴關系時的解決方案,然后自動處理軟件的依賴性問題,以解決軟件安裝或升級的問題。  yum使用方法: yum [options] [command] [packages …] install package .. 通過yum安裝軟件包 update package .. 更新軟件包 u…

    Linux干貨 2016-08-24
  • Redis基于Sentinel哨兵高可用方案

    下載最新redis版本,當前最新版本為  2.8.19  2014-12-30 安裝redis 首頁地址:http://redis.io/ 最新穩定版下載地址: http://download.redis.io/releases/redis-2.8.19.tar.gz # tar -xvf redis-2.8.19.tar.gz # cd…

    2015-03-03
  • ?mysql備份之lvm

    mysql備份之lvm 新建一個lvm磁盤,這里我建的lv為mydatalv,掛載到了/data下 [root@localhost ~]# lvs   LV       VG     Attr&nbs…

    Linux干貨 2016-07-19
  • N26-第四周作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。     ~]#cp -r /etc/skel /home/tuser1     ~]#chmod -R go=-rwx /home/tuser1…

    Linux干貨 2017-01-05
  • MySQL半同步配置

    先配置主從服務器,過程見另一篇博庫 就是先搭一個主從服務器,然后 1、先在主節點上安裝半同步復制的主節點專用插件 MariaDB [(none)]> SHOW PLUGINS;這條命令可以查看有哪些插件可以用 2、從節點也一樣先裝插件 從節點上先停止線程 STOP SLAVE; 主節點上 從節點上 START SLAVE; 這里需要手動的停止一下線程,…

    Linux干貨 2016-11-21
欧美性久久久久