Shellofamanpuri是什么意思

Linux Shell man 命令详细介绍 - 文章 - 伯乐在线
& Linux Shell man 命令详细介绍
知道linux帮助文件(man-pages,手册页)一般放在,$MANPATH/man 目录下面,而且按照领域与语言放到不同的目录里面。 看了上一章,要找那个命令使用相关手册,只要我们按照领域区分,到对于目录去查看与命令对应的文件解压,cat file 就可以看到一篇详细的文档了。 但是与快速索引查找帮助相差太远了。linux有一个很好工具,就是man 它会按照系统设计帮助目录,在各个文档里面查询,并且显示内容。接下来,主要讲一下这个命令使用以及配置说明,还有一些使用实例。
man命令使用
man命令:可以通过一些参数,快速查询linux帮助手册,并且格式化显示。
使用语法:
man [-adfhktwW] [section] [-M path] [-P pager] [-S list] [-m system] [-p string] title..
参数用法:
man命令常用参数
显示所有匹配项
显示man查照手册文件时候,搜索路径信息,不显示手册页内容
同-d,显示手册页内容
同命令whatis ,将在whatis数据库查找以关键字开同的帮助索引信息
显示帮助信息
同命令apropos 将搜索whatis数据库,模糊查找关键字
指定搜索的领域及顺序 如:-S 1:1p httpd 将搜索man1然后 man1p目录
使用troff 命令格式化输出手册页 默认:groff输出格式页
不带搜索title 打印manpath变量 带title关键字 打印找到手册文件路径,默认搜索一个文件后停止
搜索领域【限定手册类型】默认查找所有手册
man命令其它参数
显示使用 cat 命令的手册信息
指定man 命令搜索配置文件 默认是man.config
搜索一个字符串在所有手册页中,速度很慢
指定搜索手册的路径
使用程序pro显示手册页面 默认是less
使用pro程序显示HTML手册页 默认是less
使用pro程序读取HTML手册,用txt格式显示,默认是cat
指定通过groff格式化手册之前,先通过其它程序格式化手册
它带的参数非常多,其实只有上面常用参数我们才经常使用,其它很多参数几本不会去修改。
man命令获得帮助一般过程
[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'
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
- Apache Hypertext Transfer Protocol Server
(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 routines for writing to the HTTPD (or other) error log
- Apache Hypertext Transfer Protocol Server
(rpm) - Apache HTTP Server
httpd-devel
(rpm) - Development tools for the Apache HTTP server.
httpd_selinux
- Security Enhanced Linux Policy for the httpd daemon
- a fast, secure and flexible webserver
(rpm) - Lightning fast webserver with light system requirements
lighttpd-fastcgi
(rpm) - FastCGI module and spawning helper for lighttpd and PHP configuration
- 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
- 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 命令查找手册的路径
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
[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 passwdReading config file /etc/man.config.....found man directory /usr/manusing /usr/bin/less -is as pagerusing /usr/bin/less -is as browserusing /bin/cat to dump HTML pages as textpath directory /bin is in the config fileadding /usr/share/man/zh_CN to manpathadding /usr/share/man to manpathfound 'NROFF_OLD_CHARSET' in pathold 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 httpdhttpd&&&&&&&&&&&&&&&&(8)&&- Apache Hypertext Transfer Protocol Serverhttpd&&&&&&&&&&&&&& (rpm) - Apache HTTP Serverhttpd-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 httpdCGI::Carp&&&&&&&&&&&&(3pm)&&- CGI routines for writing to the HTTPD (or other) error loghttpd&&&&&&&&&&&&&&&&(8)&&- Apache Hypertext Transfer Protocol Serverhttpd&&&&&&&&&&&&&& (rpm) - Apache HTTP Serverhttpd-devel&&&&&&&& (rpm) - Development tools for the Apache HTTP server.httpd_selinux&&&&&&&&(8)&&- Security Enhanced Linux Policy for the httpd daemonlighttpd&&&&&&&&&&&& (1)&&- a fast, secure and flexible webserverlighttpd&&&&&&&&&&&&(rpm) - Lightning fast webserver with light system requirementslighttpd-fastcgi&&&&(rpm) - FastCGI module and spawning helper for lighttpd and PHP configurationncsa_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获得帮助信息
man命令搜索配置文件(man.config配置方法)
man这个命令为什么功能这么神奇,能够这么方便快捷索引出系统帮助信息,其它与它的一个配置文件分不开。我们看一下它配置文件。
[chengmo@centos5 ~]$ man -f man
- format and display the on-line manual pages
- display system documentation
- macros to format man pages
(rpm) - A set of documentation tools: man, apropos and whatis.
(rpm) - Man (manual) pages from the Linux Documentation Project.
man.config [man]
- configuration data for man
[chengmo@centos5 ~]$ man -f manman&&&&&&&&&&&&&&&&&&(1)&&- format and display the on-line manual pagesman&&&&&&&&&&&&&&&&&&(1p)&&- display system documentationman&&&&&&&&&&&&&&&&&&(7)&&- macros to format man pagesman&&&&&&&&&&&&&&&& (rpm) - A set of documentation tools: man, apropos and whatis.man-pages&&&&&&&&&& (rpm) - Man (manual) pages from the Linux Documentation Project.man.config [man]&&&& (5)&&- configuration data for man
通过该命令,我们索引到所有与man有关的手册页了。 根据前面提到的领域设置类型,(1)是man命令说明,(7)man文件使用的宏格式规定,下面有一个:man.config (5) ,就是man的配置文件了。
读取man.config文件:
[wangsl@centos5 ~]$ cat /etc/man.config | grep -v '^#'
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH_MAP
/usr/share/man
MANPATH_MAP
/usr/share/man
MANPATH_MAP
/usr/share/man
MANPATH_MAP
/usr/share/man
MANPATH_MAP
/usr/local/bin
/usr/local/share/man
MANPATH_MAP
/usr/local/sbin
/usr/local/share/man
MANPATH_MAP
/usr/X11R6/bin
/usr/X11R6/man
MANPATH_MAP
/usr/bin/X11
/usr/X11R6/man
MANPATH_MAP
/usr/bin/mh
/usr/share/man
/usr/bin/groff -Tps -mandoc
/usr/bin/nroff -c --legacy NROFF_OLD_CHARSET -mandoc 2&/dev/null
/usr/bin/geqn -Tps
/usr/bin/geqn -Tutf8
/usr/bin/gtbl
/usr/bin/grefer
/usr/bin/gpic
/usr/bin/less -is
/usr/bin/less -is
/usr/bin/cmp -s
/usr/bin/bzip2
COMPRESS_EXT
1:1p:8:2:3:3p:4:5:6:7:9:0p:n:l:p:o:1x:2x:3x:4x:5x:6x:7x:8x
/usr/bin/gunzip -c
/usr/bin/bzip2 -c -d
123456789101112131415161718192021222324252627282930313233343536373839
[wangsl@centos5 ~]$ cat /etc/man.config | grep -v '^#'FHSMANPATH /usr/manMANPATH /usr/share/manMANPATH /usr/local/manMANPATH /usr/local/share/manMANPATH /usr/X11R6/manMANPATH_MAP&&&& /bin&&&&&&&&&&&&&&&&&&&&/usr/share/manMANPATH_MAP&&&& /sbin&&&&&&&&&&&&&&&&&& /usr/share/manMANPATH_MAP&&&& /usr/bin&&&&&&&&&&&&&&&&/usr/share/manMANPATH_MAP&&&& /usr/sbin&&&&&&&&&&&&&& /usr/share/manMANPATH_MAP&&&& /usr/local/bin&&&&&&&&&&/usr/local/share/manMANPATH_MAP&&&& /usr/local/sbin&&&&&&&& /usr/local/share/manMANPATH_MAP&&&& /usr/X11R6/bin&&&&&&&&&&/usr/X11R6/manMANPATH_MAP&&&& /usr/bin/X11&&&&&&&&&&&&/usr/X11R6/manMANPATH_MAP&&&& /usr/bin/mh&&&&&&&&&&&& /usr/share/manTROFF&&&&&&&&&& /usr/bin/groff -Tps -mandocNROFF&&&&&&&&&& /usr/bin/nroff -c --legacy NROFF_OLD_CHARSET -mandoc 2&/dev/nullEQN&&&&&&&&&&&& /usr/bin/geqn -TpsNEQN&&&&&&&&&&&&/usr/bin/geqn -Tutf8TBL&&&&&&&&&&&& /usr/bin/gtblREFER&&&&&&&&&& /usr/bin/greferPIC&&&&&&&&&&&& /usr/bin/gpicVGRINDGRAPPAGER&&&&&&&&&& /usr/bin/less -isBROWSER&&&&&&&& /usr/bin/less -isHTMLPAGER&&&&&& /bin/catCAT&&&&&&&&&&&& /bin/catCMP&&&&&&&&&&&& /usr/bin/cmp -sCOMPRESS&&&&&&&&/usr/bin/bzip2COMPRESS_EXT&&&&.bz2MANSECT&&&&&&&& 1:1p:8:2:3:3p:4:5:6:7:9:0p:n:l:p:o:1x:2x:3x:4x:5x:6x:7x:8x.gz&&&&&&&&&&&& /usr/bin/gunzip -c.bz2&&&&&&&&&&&&/usr/bin/bzip2 -c -d.z.Z&&&&&&&&&&&&&&/bin/zcat.F.Y
配置文件分类:
MANPATH 关键字
指定手册默认存放路径,man启动就会在这些目录中索引手册页,可以通过添加一行:MANPATH /home/chengmo/man 指定加入自己的手册路径,通过man -M可以添加自己的手册路径
MANPATH_MAP关键字
指定帮助手册与命令对应目录,如果自己增加搜索目录,这里需要增加对应方式
格式化手册页输出
linux系统手册页,大家在看到时候有高亮,然后还有加粗,下划线,倾斜,空行等固定格式。其实这些在本来的手册页文件里面,只是保存为一系列的代号。大家不妨解压个gz手册文件,然后通过cat查看下内容。你会发现显示里面有如下内容中(点开头,然后一系列数字,而且整个页面显示杂乱无章,跟我们man看到完全不一样),其它这些代号对应是linux文件里面的宏指令代码,如:
.BI 粗体跟斜体
.BR 粗体跟正体
.IB 斜体跟粗体
.IR 斜体跟正体
.RB 正体跟粗体
.RI 正体跟斜体
.SM 小(缩放到正常大小的9/10)
.SB 小跟黑体(所跟的黑体不会缩小)
如果不清楚这个关系,把这些宏指令比拟为:html语言一些标签,在记事本中打开,大家都看不明白,但是如果用ie查看。就一目了然了。
这些宏指令在显示时候,必须通过一系列命令做格式转换,这里必须提到是:groff系列命令(它的工作有点像IE):
groff简介:
Groff (GNU Troff) 是 Troff 的最新开放源码实现,Troff 是从相同的输入源为各种设备生成打印和屏幕文档的一种文档格式化输出系统。
Groff 是一种用于格式化输出文档的编程语言。它由一套工具组成,而不是单个的应用程序,groff 工具是使用这些工具的前端。其中包括处理特殊的输入文本的预处理器、用于处理输入的称为 troff 的主排版引擎、以及将 troff 的输出转换为打印和屏幕输出的各种格式的后处理器。
您可以在文本编辑器中编写输入或者从程序生成输入,无论采用哪种方式,文档的编写过程都发生在 Groff 系统之外。文档使用纯文本进行编写并使用 Groff 语言进行标记,后者指定了文档的格式和外观(请参见为 Groff 编写输入部分)。然后将该输入文本发送到 Groff,以便对其进行处理从而获得所需的输出。
Groff包含几个处理文本格式的程序。Groff把标准的文本和特殊的命令翻译成格式化的输出,像你在 man 手册页里看到的那样。
安装下列程序: addftinfo, afmtodit, eqn, eqn2graph, geqn (link to eqn), grn, grodvi, groff, groffer, grog, grolbp, grolj4, grops, grotty, gtbl (link to tbl), hpftodit, indxbib, lkbib, lookbib, mmroff, neqn, nroff, pfbtops, pic, pic2graph, post-grohtml, pre-grohtml, refer, soelim, tbl, tfmtodit, troff and zsoelim (link to soelim)
这里只是解析man.config常见的解析命令:
gpic 将内嵌于troff或者TeX输入文件中的图像编译成troff或者TeX理解的指令。
gtbl 实现table表格输出。
neqn 将方程格式化,使其成为适应ASCII输出的脚本,如果文档要表示一些数字开方,根号之类需要它了
refer 将一个文件拷贝到标准输出,并丢弃.[和.]之间作为引用的内容和在.R1和.R2之间解释如何处理这些引用的命令。
troff groff依照合适的顺序并使用合适的参数来执行预处理程序和后处理程序。
PAGER、BROWER、HTMLPAGER
分别制定最终标准手册页,HTML手册页,HTML as TXT手册页 由那个程序显示。其实基本都是交给了:less这个作为手册页显示程序。当我们打开了手册页后,对它进行翻页查找等操作,其实就是运用less 程序快捷键完成的。如果命令行man –[PBH] 可以对当前索引,分别用新的程序覆盖系统设置。
COMPRESS,COMPRESS_EXT
设置压缩文件,已经压缩文件生成扩展名,如果需要将手册输出其它格式时候会用到
指定man 搜索手册目录顺序,假设设置是:
mansect 1:1p:8:2:3:3p:4:5:6:7:9:0p:n:l:p:o:1x:2x:3x:4x:5x:6x:7x:8x
如果直接man command1 ,它将按照这里指定的顺序查找手册页,先是man1,然后man1p…… 直到找到一个页面,就停止搜索。除非加了-a 参数。如果调用man -S 1:1p 是可以覆盖这项设置的
这个是如果手册页面是这里程序的,用什么程序进行解压。
我们还记得上次man -d 的参数吧!运行最后会输入一个脚本:
(cd /usr/share/man && (echo “.ll 11.8i”; echo “.nr LL 11.8i”; echo “.pl 1100i”; /usr/bin/gunzip -c ‘/usr/share/man/man1/man.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命令执行后 ,通过各个格式化指令组合,最终shell脚本运行的命令。
突然想到一个问题,man之所以强大,与它的松散配置分不开,它只是实现了搜索查找,而解压由:gunzip,格式化是由:groff处理,显示有less处理。
说到这里,man好像都说完了,对了,显示的页面怎么操作呢?接下来,我们在看看,less常用命令
man显示页面操作(less命令使用)
我们找到了自己的帮助文件了,而且已经显示了页面。在这个黑屏页面里面,我怎么样实现查找,跳转等操作呢?
其实,它现在已经进入了less命令管理范围了(可能有朋友认为是vi的,因为它们快捷键很相似,其实是less的)
下面说下less命令操作:
光标移动操作:
e ^E j ^N CR * 前进一行(或N行)
y ^Y k ^K ^P * 后退一行(或N行)
f ^F ^V SPACE * 前进一个窗口(或N行)
b ^B ESC-v * 后退一个窗口(或N行)
z * 前进一个窗口(将窗口设置到N)
w * 后退一个窗口(将窗口设置到N)
ESC-SPACE * 前进一个窗口,在文件末尾不停止
d ^D * 前进半个窗口(将这半个窗口设置到N)
u ^U * 后退半个窗口(将这半个窗口设置到N)
ESC-) RightArrow * 向左半个屏幕宽(或N个位置)
ESC-( LeftArrow * 向右半个屏幕宽(或N个位置)
F 一直前进,像”tail -f”一样
移动操作基本与vi一样的。
查找操作:
/pattern * 向前查找包含pattern的行.
?pattern * 向后查找包含pattern的行.
n * 查找下一个pattern行.
N * 查找上一个pattern行.
ESC-n * 同n.
ESC-N * 同N
ESC-u 取消所有搜索的高亮显示
调动操作:
g & ESC-& * 跳转到文件第一行
G & ESC-& * 跳转到文件最后一行
p % * 跳转到文件最开始
其它操作:
:n * 打开跳转到下一个文件
:p * 打开跳转到上一个文件
:x * 跳转到第一个打开的文件
h H 显示帮助
q :q Q :Q ZZ 退出当前打开文件
less可以打开多个文件,在多个文件操作中,可以使用这些命令。如man -a passwd 实际会查到多个手册,都会有less打开。可以通过这类命令实现打开与关闭。
以上是在使用man命令时候,一些总结,大家有好的方法欢迎交流。
可能感兴趣的话题
关于伯乐在线博客
在这个信息爆炸的时代,人们已然被大量、快速并且简短的信息所包围。然而,我们相信:过多“快餐”式的阅读只会令人“虚胖”,缺乏实质的内涵。伯乐在线内容团队正试图以我们微薄的力量,把优秀的原创文章和译文分享给读者,为“快餐”添加一些“营养”元素。
新浪微博:
推荐微信号
(加好友请注明来意)
– 好的话题、有启发的回复、值得信赖的圈子
– 分享和发现有价值的内容与观点
– 为IT单身男女服务的征婚传播平台
– 优秀的工具资源导航
– 翻译传播优秀的外文文章
– 国内外的精选文章
– UI,网页,交互和用户体验
– 专注iOS技术分享
– 专注Android技术分享
– JavaScript, HTML5, CSS
– 专注Java技术分享
– 专注Python技术分享
& 2017 伯乐在线相关词典网站:

我要回帖

更多关于 amanstino 的文章

 

随机推荐