Linux man命令的使用总结

一. 前言

        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 groff

 Main 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, --location
                             print physical location of man page(s)
  -W, --where-cat, --location-cat
                             print 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 ENCODING

 Finding 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' => 'man
                             foo-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 version

Mandatory 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/ps2pdf



ghostscript-9.25-5.el7.x86_64 : Interpreter for PostScript language & PDF
Repo        : base
Matched from:
Filename    : /usr/bin/ps2pdf



ghostscript-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安装。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值