一. 前言

Linux man命令对于方便查看Linux的命令和系统函数的用法起到了很大的作用,可以说是Linux使用者的一把利器。但是,对于初学者甚至接触linux较久的人,对于man的用法还只是停留在"man xxx函数"的阶段,设置某些函数还不知道怎么通过man命令查到。

下面我列举几个man命令使用的痛点:

1. 有些命令的手册通过man命令只能查到基础部分,扩展的部分不知道怎么查询。所以想要系统的学习某个命令的使用(选项的作用,配置文件等等)非常麻烦。

2. 有些命令和函数的用途非常广,man命令不能查到自己想要的,例如ioctl函数。

3. 通过man命令打开的手册,只能通过类似vim打开文件的方式阅读,手册内容短一点还好,若是较长,翻阅起来非常麻烦,man命令退出后,下次打开将又是定位在手册开头。man命令适合某个命令或函数的查阅,完整的学习某个命令或函数则非常不方便。

二. 使用技巧

要解决上述痛点1和2,首先我们需要知道以下两点:

1. man手册在系统的位置,也就是man命令到哪些路径查找手册。

man --help输出如下:

[root@192 ~]# man --help
Usage: man [OPTION...] [SECTION] PAGE...-C, --config-file=FILE     use this user configuration file-d, --debug                emit debugging messages-D, --default              reset all options to their default values--warnings[=WARNINGS]  enable warnings from groffMain modes of operation:-f, --whatis               equivalent to whatis-k, --apropos              equivalent to apropos-K, --global-apropos       search for text in all pages-l, --local-file           interpret PAGE argument(s) as local filename(s)-w, --where, --path, --locationprint physical location of man page(s)-W, --where-cat, --location-catprint physical location of cat file(s)-c, --catman               used by catman to reformat out of date cat pages-R, --recode=ENCODING      output source page encoded in ENCODINGFinding manual pages:-L, --locale=LOCALE        define the locale for this particular man search-m, --systems=SYSTEM       use manual pages from other systems-M, --manpath=PATH         set search path for manual pages to PATH-S, -s, --sections=LIST    use colon separated section list-e, --extension=EXTENSION  limit search to extension type EXTENSION-i, --ignore-case          look for pages case-insensitively (default)-I, --match-case           look for pages case-sensitively--regex                show all pages matching regex--wildcard             show all pages matching wildcard--names-only           make --regex and --wildcard match page names only,not descriptions-a, --all                  find all matching manual pages-u, --update               force a cache consistency check--no-subpages          don't try subpages, e.g. 'man foo bar' => 'manfoo-bar'Controlling formatted output:-P, --pager=PAGER          use program PAGER to display output-r, --prompt=STRING        provide the `less' pager with a prompt-7, --ascii                display ASCII translation of certain latin1 chars-E, --encoding=ENCODING    use selected output encoding--no-hyphenation, --nh turn off hyphenation--no-justification,                              --nj   turn off justification-p, --preprocessor=STRING  STRING indicates which preprocessors to run:e - [n]eqn, p - pic, t - tbl,
g - grap, r - refer, v - vgrind-t, --troff                use groff to format pages-T, --troff-device[=DEVICE]   use groff with selected device-H, --html[=BROWSER]       use elinks or BROWSER to display HTML output-X, --gxditview[=RESOLUTION]   use groff and display through gxditview(X11):-X = -TX75, -X100 = -TX100, -X100-12 = -TX100-12-Z, --ditroff              use groff and force it to produce ditroff-?, --help                 give this help list--usage                give a short usage message-V, --version              print program versionMandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.Report bugs to cjwatson@debian.org.

通过man --help命令可以看到,-w可以输出man手册的路径。

[root@192 ~]# man -w
/usr/local/man:/usr/local/share/man:/usr/share/man/overrides:/usr/share/man

man手册路径类似环境变量格式输出了,man手册的路径可以是/usr/local/man 或者 /usr/local/share/man 或者 /usr/share/man/overrides 或者 /usr/share/man。

2. 我们可以通过find命令查找文件的方式来查找man手册。因为man手册是以文件的形式存在的,man手册的格式的形式为"keyword.page.gz"。

举例:

如果想查找ioctl的用法,我们可以使用find命令查找ioct关键字,如下:

[root@192 ~]# find /usr/local/man -name *ioctl
[root@192 ~]# find /usr/local/share/man -name *ioctl*
[root@192 ~]# find /usr/share/man/overrides -name *ioctl*
[root@192 ~]# find /usr/share/man -name *ioctl*
/usr/share/man/man2/ioctl.2.gz
/usr/share/man/man2/ioctl_list.2.gz
/usr/share/man/man3/use_tioctl.3x.gz
/usr/share/man/man3p/ioctl.3p.gz
/usr/share/man/man4/console_ioctl.4.gz
/usr/share/man/man4/tty_ioctl.4.gz

从输出可知,和ioctl相关的手册分别是 ioctl.2.gz,ioctl_list.2.gz,use_tioctl.3x.gz,ioctl.3p.gz,console_ioctl.4.gz,tty_ioctl.4.gz。我们可以通过man命令系统的学习ioctl函数的各种使用方法。

要解决痛点3,我们可以将man手册输出为pdf文档,可以方便我们平时阅读。

[root@192 ~]# man -t ioctl | ps2pdf - ioctl.pdf

以上命令的作用是使用GROFF格式化ioctl函数man手册,并且使用ps2pdf命令以ioctl.pdf输出man手册格式化的内容。

三. 总结

man命令对于Linux使用者来说非常重要,但是使用过程中,准确的找到man手册和man手册的阅读的方便性方面不够友好。这两个问题可以通过在man手册的安装路径通过关键字查找手册,把man书册以pdf格式输出来解决。

PS:

CentOS 7 ps2pdf安装方式:

1. 通过yum provides ps2pdf找到ps2pdf对应的rpm包,32位 对应ghostscript-9.25-5.el7.i686 和 64位对应 ghostscript-9.25-5.el7.x86_64

[root@192 ~]# yum provides ps2pdf
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors* base: mirrors.ustc.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.aliyun.com
ghostscript-9.25-5.el7.i686 : Interpreter for PostScript language & PDF
Repo        : base
Matched from:
Filename    : /usr/bin/ps2pdfghostscript-9.25-5.el7.x86_64 : Interpreter for PostScript language & PDF
Repo        : base
Matched from:
Filename    : /usr/bin/ps2pdfghostscript-9.25-5.el7.x86_64 : Interpreter for PostScript language & PDF
Repo        : @base
Matched from:
Filename    : /usr/bin/ps2pdf

2. 通过yum install ghostscript-9.25-5.el7.x86_64安装。

Linux man命令的使用总结相关推荐

  1. linux常用命令(转载)

    Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错.我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短 ...

  2. linux if 命令判断条件总结

    linux if命令 关于文件属性的判断式 -a 如果文件存在 -b 如果文件存在,且该文件是区域设备文件 -c 当file存在并且是字符设备文件时返回真 -d 当pathname存在并且是一个目录时 ...

  3. linux paste变量,Linux paste命令详解

     Linux 命令大全 小白告诉你:Linux paste 命令用于合并文件的列. paste 指令会把每个文件以列对列的方式,一列列地加以合并. 语法 paste [-s][-d ][--help] ...

  4. linux unset命令,Linux unset命令

    Linux unset命令 Linux unset命令用于删除变量或函数. unset为shell内建指令,可删除变量或函数. 语法unset [-fv][变量或函数名称] 参数:-f 仅删除函数. ...

  5. linux wc 命令简介

    此wc命令不是让大家没有食欲的地方.而是linux下一个简单的小命令. NAME wc - word, line, character, and byte count SYNOPSIS wc [-cl ...

  6. linux mysql 命令 大全

    linux mysql 命令 大全 1.linux下启动mysql的命令:   mysqladmin start /ect/init.d/mysql start (前面为mysql的安装路径) 2.l ...

  7. Linux Find 命令精通指南

    作者:Sheryl Calish Linux find 命令是所有 Linux 命令中最有用的一个,同时也是最混乱的一个.它很难,因为它的语法与其他 Linux 命令的标准语法不同.但是,它很强大,因 ...

  8. linux ps命令大全,Linux ps命令例子汇总

    Linux ps命令主要用于查看系统运行的进程,确定进程运行的状态机是否占用过多资源等?下面学习啦小编通过实例来给大家详细介绍下Linux的ps命令,一起来了解下吧. Linux提供了当前进程的同时, ...

  9. linux用户在哪个文件夹,LINUX中用命令成功建立一个用户后信息会记录在哪个文件中...

    LINUX中用命令成功建立一个用户后信息会记录在哪个文件中 发布时间:2007-07-28 10:14:57来源:红联作者:MPiops 增加用户帐号后 新建用户的命令十分简单,在命令行下使用 use ...

  10. Linux常见命令(二)

    随着Linux应用的扩展许多同学开始接触Linux,根据学习Windwos的经验往往有一些茫然的感觉:不知从何处开始学起.虽然Linux桌面应用发展很快,但是命令在Linux中依然有很强的生命力.Li ...

最新文章

  1. Apollo 你了解下这些内容就完美了
  2. SSM解决Mapper映射文件不发布
  3. string stringbuffer stringbuilder 区别
  4. python 播放声音_如何用Python播放声音?
  5. (转)淘淘商城系列——首页轮播图展示
  6. 理解函数的相关概念python_Python函数的概念和使用
  7. 【Android Camera】之 Preview
  8. 廖雪峰git学习(3)分支管理【待续】
  9. 如何彻底删除SQL Server2005
  10. 10068---谈谈Runtime类中的freeMemory,totalMemory,maxMemory几个方法
  11. SpringBoot签名验签
  12. JDBC连接到sql server2008
  13. 颜宁:学术圈问题很多,也不分国籍,希望年轻一代守住底线
  14. dos系统的界面字体设置
  15. 设计模式分析——迭代器模式(Iterator)
  16. 百度崔珊珊讲给年轻人的九个故事:和百度一起成长,然后改变世界
  17. 炫光鬼影原因分析转载
  18. adf机器_美能达163维修模式中文说明
  19. 7-5 小字辈 (25 分)
  20. 原来“李”是这样的蜂糖李

热门文章

  1. 【研究生】MBA论文与管理硕士论文是不是一回事?很多人都弄错了!
  2. MySQL 中文设置
  3. download-git-repo 用法
  4. 计算机怎么设置内存数据恢复,最新手机内存数据恢复方法【详细介绍】
  5. 苹果被罚7800多万?都是防水惹的祸
  6. 虚拟机u16.04中关于只读文件interfaces的修改
  7. js案例 求出最大数和最小数
  8. 双十一全网最全蓝牙耳机盘点,2020不容错过的精品游戏蓝牙耳机
  9. OpenMV的单颜色识别讲解
  10. 你也想做自媒体短视频赚钱?先问弄明白3个问题