从 man 指令起步(info简介),maninfo


前言

  小生认为一切指令的学习首先要从帮助入手,深入了解它的功能,即使是在实际项目中我们都离不开它的帮助。因为我们不一定能够记住全部指令的全部的相关功能,因此,查看指令的帮助是我们的不二选择。

正文

  下面,我们就来看看  man 和 info 这两个指令。

首先,我们可以通过 man man指令来查看相关说明。可能有的朋友英语不算很好,又想尽快的掌握linux指令,我们可以下载中文man帮助手册,安装后设置别名(如cman),使用其便可显示中文(安装过程请关注下一篇博客)。不过,小生建议不要过度依赖中文手册,读懂英文文献才是王道。

man(1) 

NAME
       man - format and display the on-line manual pages

MANUAL SECTIONS
       The standard sections of the manual include:

       1      User Commands        //标准指令---用户在shell环境中可以执行的指令或可执行文件

       2      System Calls         //系统调用---由内核提供的函数 (open,write之类,查看头文件)

       3      C Library Functions     //C 函数 ---(printf,fread) 

       4      Devices and Special Files  //设备和特殊文件说明 ---通常在/dev下的文件

       5      File Formats and Conventions  //文件格式和约定 ---配置文件或者是某些文件的格式 比如passwd 

       6      Games et. Al.          //游戏等娱乐 ---给游戏留的,由各个游戏自己定义

       7      Miscellanea           // 杂项 ---例如man、environ、Linux文件系统、网络协议、ASCII code等说明

       8      System Administration tools and Deamons  //系统管理员可用的管理命令---ifconfig 

例如 :

[linux@linux ~]$ man printf    --左上角默认PRINTF(1),是shell中的指令 
[linux@linux ~]$ man 3 printf  --代表C语言中的函数

man page 主要分为以下几个部分


NAME
简短的指令、数据名称说明
SYNOPSIS 指令下达语法简介
DESCRIPTION 详尽完整的说明!!
AUTHOR 作者
REPORTING BUGS 反馈错误
COPYRIGHT 版权
SEE ALSO 与指令相关的其他说明

 

 

 

 

 

 

 

 

 

帮助文档中相关按键的说明

按键 相应的动作
SPACE 向下翻页
Page Down 向下翻页   方向键↓ 向下移动
Page Up 向上翻页   方向键↑ 向上移动
Home 回到首页
End 转到最后一页
/string 向下搜寻字符串
?string 向上搜寻字符串
n , N 查看下一个或上一个搜寻到的字符串,与/string、?string配合使用
q 退出

 

 

 

 

 

 

 

 

 

查看以关键字开头的所有说明文件

1 [linux@linux ~]$ man -f man
2 man                  (1)  - format and display the on-line manual pages
3 man                  (1p)  - display system documentation
4 man                  (7)  - macros to format man pages
5 man.config [man]     (5)  - configuration data for man
6 man [manpath]        (1)  - format and display the on-line manual pages
7 man-pages            (7)  - conventions for writing Linux man pages

 

根据关键字(不一定开头)显示出相关说明文档

1 [linux@linux ~]$ man -k man
2 ...3 xsetwacom            (1)  - commandline utility to query and modify wacom driver settings
4 xsltproc             (1)  - command line XSLT processor
5 yum-groups-manager   (1)  - create and edit yum's group metadata

执行后发现最后一列中有man关键字的也会列举出来,这不是我们想要的,因此我想到鸟哥在后面章节所用到的截取命令(cut 、grep),这就是第一遍读书的效果,知道有相关的命令,然后去查找、去实现。

1 [linux@linux ~]$ man -k man | cut -d ' ' -f 1 | grep 'man'
2 cmakecommands
3 command
4 command
5 ecryptfs-manager
6 ...

在man中还可以执行指令  ----  !指令

关于man的相关参数说明我参考了http://www.cnblogs.com/chengmo 的博客,现引用在下。

使用语法:

man [-adfhktwW] [section] [-M path] [-P pager] [-S list]  [-m system] [-p string] title..

参数用法:

 

参数 备注
man命令常用参数
-a 显示所有匹配项
-d 显示man查照手册文件时候,搜索路径信息,不显示手册页内容
-D 同-d,显示手册页内容
-f 同命令whatis ,将在whatis数据库查找以关键字开同的帮助索引信息
-h 显示帮助信息
-k 同命令apropos 将搜索whatis数据库,模糊查找关键字
-S list 指定搜索的领域及顺序 如:-S 1:1p httpd 将搜索man1然后 man1p目录
-t 使用troff 命令格式化输出手册页 默认:groff输出格式页
-w 不带搜索title 打印manpath变量 带title关键字 打印找到手册文件路径,默认搜索一个文件后停止
-W 同-w
section 搜索领域【限定手册类型】默认查找所有手册
man命令其它参数
-c 显示使用 cat 命令的手册信息
-C 指定man 命令搜索配置文件 默认是man.config
-K 搜索一个字符串在所有手册页中,速度很慢
-M 指定搜索手册的路径
-P pro 使用程序pro显示手册页面 默认是less
-B pro 使用pro程序显示HTML手册页 默认是less
-H pro 使用pro程序读取HTML手册,用txt格式显示,默认是cat
-p str 指定通过groff格式化手册之前,先通过其它程序格式化手册
  • man命令获得帮助一般过程

 

实例代码

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 [chengmo@centos5 ~]$ man -w passwd /usr/share/man/man1/passwd.1.gz #显示passwd帮助文件路径,passwd.1 通过名称知道这个是passwd命令帮助手册,那它的其它命令的呢?   [chengmo@centos5 ~]$ man -aw passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz #加入-a获得所有帮助手册文件地址,默认只会查找一个   [chengmo@centos5 ~]$ man 5 passwd #只得到passwd配置文件帮助信息,可以加入领域类型限制,如果知道5,默认是查询man5 文件配置信息说明 手册目录     [chengmo@centos5 ~]$ man -d passwd Reading config file /etc/man.config ..... found man directory /usr/man using /usr/bin/less -is as pager using /usr/bin/less -is as browser using /bin/cat to dump HTML pages as text path directory /bin is in the config file adding /usr/share/man/zh_CN to manpath adding /usr/share/man to manpath found 'NROFF_OLD_CHARSET' in path old charset of '/usr/share/man/man1/passwd.1.gz' is 'ISO-8859-1' man: not executing command:   (cd /usr/share/man && (echo ".ll 11.8i"; echo ".nr LL 11.8i"; echo ".pl 1100i"; /usr/bin/gunzip -c '/usr/share/man/man1/passwd.1.gz'; echo ".\\\""; echo ".pl \n(nlu+10") | /usr/bin/gtbl | /usr/bin/nroff -c --legacy ISO-8859-1 -mandoc 2>/dev/null | /usr/bin/less -is)   #man -d 返回man 执行过程搜索查找方法,以及查询手册通过怎么样格式化语句显示。都会列出来 #可以看到,指定pages,borwser输出命令对应文件,html输出文件,搜索路径,由于我当前LANG=zh_CN.gb2312因此,添加了zh_CN目录搜索 #最终执行命令时候,通过一系列格式转换命令,最终有less显示       [chengmo@centos5 ~]$ man -S 1:2 passwd #在领域类型是:1:2 范围内查找手册,对应目录分别是man1 ,man2     [chengmo@centos5 ~]$ man -f httpd httpd                (8)  - Apache Hypertext Transfer Protocol Server httpd               (rpm) - Apache HTTP Server httpd-devel         (rpm) - Development tools for the Apache HTTP server. #在whatis数据库(有所有网站man帮助以及cat,doc帮助信息索引)中查询,文件标题以:http开头信息的文档 #中间的(8) 对应我们可以用:man 8 httpd 调用,对于显示(rpm)实际上显示有个httpd帮助信息,是属于一个httpd rpm安装包,通过man rpm httpd查看不了。可以通过rpm -ql httpd 查找安装包     [chengmo@centos5 ~]$ man -k httpd CGI::Carp            (3pm)  - CGI routines for writing to the HTTPD (or other) error log httpd                (8)  - Apache Hypertext Transfer Protocol Server httpd               (rpm) - Apache HTTP Server httpd-devel         (rpm) - Development tools for the Apache HTTP server. httpd_selinux        (8)  - Security Enhanced Linux Policy for the httpd daemon lighttpd             (1)  - a fast, secure and flexible webserver lighttpd            (rpm) - Lightning fast webserver with light system requirements lighttpd-fastcgi    (rpm) - FastCGI module and spawning helper for lighttpd and PHP configuration ncsa_auth            (8)  - NCSA httpd-style password file authentication helper for Squid #在whatis数据库中,查询包含httpd所有帮助手册,以及安装包. 可以通过:rpm -ql lighttpd   [chengmo@centos5 ~]$ rpm -ql lighttpd | grep gz /usr/share/man/man1/lighttpd.1.gz #其实这个包刚好是:lighttpd             (1)  - a fast, secure and flexible webserver 帮助手册     [chengmo@centos5 ~]$ man -w /usr/kerberos/man:/usr/local/share/man:/usr/share/man/zh_CN:/usr/share/man:/usr/local/man #显示man 命令查找手册的路径

 

对于:whatis数据库,以及中文化linux帮助文件这里先不分析。

一般遇到一个不是很熟悉命令可以先通过:

man -k command1  查询所有类似帮助文件信息,这样输出最多也可以用:

man -f  command1 查询以command1开头所有相关帮助信息列表 如果发现有类似:command1 (5)

man 5 command1 通过直接定位5获得帮助信息

 

info

  以主题的形式把几个命令组织在一起,以便于我们阅读,在主题内以node(节点)的形式把本主题的几个命令串联在一起。因为小生对info命令并不是很了解,在这里就不过多涉猎,等到哪天认识到它的真谛,还会回来补全介绍。

主要快捷键设置如下

按键 相应的动作
Space 向下翻页
Page Down 向下翻页
Page Up 向上翻页
tab 在node间切换,有node的地方,通常会以*显示
Enter 当光标在node上时,按下Enter进入该node
b 移动光标到该info画面当中的第一个node处
e 移动光标到该info画面当中的最后一个node处
n 切换到下一个node
p 切换到上一个node
u 向上移动一层
s(/) 在info page中进行搜寻
h 显示求助选单
指令一览表
q 退出

 

 

  

 

 

 

 

 

 

 

 

 

 

如果有重要的知识点没有提到,还请各位在评论中指出,我会根据建议再次维护,尽量做到尽善尽美!谢谢

 

相关内容