linux whatis与whatis database 使用及查询方法(man使用实例)

 更新时间:2015年10月14日 20:55:52   投稿:mdxy-dxy  
在学习man命令时候,估计很多朋友都发现有man –f ,man –k 参数,可以查出很多数据。这些有的与man手册页相同,有些不是属于手册页的。它们数据怎么收集来的,并且whatis是怎么样工作的

通过man查找帮助过程:

[chengmo@centos5 ~]$ man -h
...
 f:same as whatis(1)
...

#觉得比较奇怪,whatis是什么呢?

[chengmo@centos5 ~]$ man whatis
#查询得到是:
#whatis - search the whatis database for complete words.
#它是查询whatis数据库的工具

#The whatis database is created using the command /usr/sbin/makewhatis.
#里面还说,whatis数据库 是通过/usr/bin/makewhatis建立的

收获:whatis数据库,并且有makewhatis创建,whatis脚本是用作查询的
 

makewhatis是怎么样工作的呢?

[chengmo@centos5 ~]$ man makewhatis

#得到:

makewhatis reads all the manual pages contained in the given sections of manpath or the preformatted pages con-tained in the given sections of catpath.  For each page, it writes a line in the  whatis  database;  each  line consists  of  the  name  of the page and a short description, separated by a dash. The description is extracted  using the content of the NAME section of the manual page.

#大概意思是:makewhatis 从手册页配置的路径以及领域范围,搜集所有手册页索引信息,每个手册页在数据库加入一行,这行会包括手册页里面name,以及简单描述。

收获:知道这个数据库是建立是索引,并且每个数据库写入一行(a line) ,会不会这个数据库就是文本文件呢?现在到这里,我们不知道数据库保存地方,也不知道它结构,只有看看whatis命令,看它是不是有源码信息
怎么得到whatis程序源码?

[chengmo@centos5 ~]$ type whatis
whatis is /usr/bin/whatis

#告诉路径我们看看内容


[chengmo@centos5 ~]$ vi /usr/bin/whatis

  1 #!/bin/sh
  2 #
  3 # apropos -- search the whatis database for keywords.
  4 # whatis  -- idem, but match only commands (as whole words).

……

#它是个sh脚本,

#得到:

#grep “关键词“ /var/cache/man/whatis

#它实际在查找这个文件,/var/cache/man/whatis就是上面说的whatis 数据库

[chengmo@centos5 ~]$ head /var/cache/man/whatis
$notes_name [Module::Build::Notes] (3pm)  - Configuration for $module_name
*_unlocked [unlocked_stdio] (3)  - non-locking stdio functions

#whatis数据库就是一个文本文件记录手册页的索引信息

 

whatis数据库是什么时候创建的呢?

[chengmo@centos5 ~]$ ls -al /var/cache/man/whatis
-rw-r--r-- 1 root root 1057156 10-27 04:06 /var/cache/man/whatis

#发现创建时间是凌晨4点左右,看了这个是系统创建的,那么少不了cron怀疑了

 

[chengmo@centos5 ~]$ cat /etc/crontab  
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

 

有run-parts脚本运行/etc/cron.daily目录下面的文件

[chengmo@centos5 ~]$ cd /etc/cron.daily/

[chengmo@centos5 cron.daily]$ cat makewhatis.cron
#!/bin/bash

LOCKFILE=/var/lock/makewhatis.lock

makewhatis -u -w

……

找到了这个是由这个脚本运行的

以上是通过man命令查找帮助信息的一个过程,有问题,首先分析帮助是个不错的选择。

作者:chengmo QQ:8292669

相关文章

  • shell实现FizzBuzzWhizz问题示例(拉勾网面试题)

    shell实现FizzBuzzWhizz问题示例(拉勾网面试题)

    这篇文章主要介绍了shell实现FizzBuzzWhizz问题示例(拉勾网面试题),需要的朋友可以参考下
    2014-05-05
  • 编写shell脚本将VPS上的数据备份到Dropbox网盘的方法

    编写shell脚本将VPS上的数据备份到Dropbox网盘的方法

    这篇文章主要介绍了编写shell脚本将VPS上的数据备份到Dropbox网盘的方法,注意Dropbox在国内访问的网络相关问题,需要的朋友可以参考下
    2015-07-07
  • Shell命令解析之set命令的用法和参数详解

    Shell命令解析之set命令的用法和参数详解

    set 命令作用主要是显示系统中已经存在的 shell 变量,以及设置 shell 变量的新变量值,这篇文章主要介绍了Shell命令解析之set命令的用法和参数详解,需要的朋友可以参考下
    2023-10-10
  • shell脚本读取命令行参数的实现

    shell脚本读取命令行参数的实现

    本文主要介绍了shell脚本读取命令行参数的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-07-07
  • ping发现掉包报警的shell代码

    ping发现掉包报警的shell代码

    一般用来判断服务器是否稳定,加入crontab中让其10分钟跑一次,需要的朋友可以参考下
    2013-01-01
  • Shell中printf和test命令的实际应用详解

    Shell中printf和test命令的实际应用详解

    本文主要介绍了Shell中printf和test命令的实际应用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-09-09
  • shell中set设置-e和 -x的用法

    shell中set设置-e和 -x的用法

    本文主要介绍了shell中set设置-e和 -x的用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-06-06
  • linux bash中too many arguments问题的解决方法

    linux bash中too many arguments问题的解决方法

    本文介绍下在linux bash shell中出现too many arguments问题的解决办法,有需要的朋友参考学习下
    2013-11-11
  • shell中如何使用date获取时间戳

    shell中如何使用date获取时间戳

    这篇文章主要介绍了shell中如何使用date获取时间戳,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-09-09
  • 每天学一个 Linux 命令之more命令

    每天学一个 Linux 命令之more命令

    more命令,功能类似 cat ,more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能
    2016-12-12

最新评论