linux whatis与whatis database 使用及查询方法(man使用实例)
通过man查找帮助过程:
[chengmo@centos5~]$man-h
...
f:sameaswhatis(1)
...
#觉得比较奇怪,whatis是什么呢?
[chengmo@centos5~]$manwhatis
#查询得到是:
#whatis-searchthewhatisdatabaseforcompletewords.
#它是查询whatis数据库的工具
#Thewhatisdatabaseiscreatedusingthecommand/usr/sbin/makewhatis.
#里面还说,whatis数据库是通过/usr/bin/makewhatis建立的
收获:whatis数据库,并且有makewhatis创建,whatis脚本是用作查询的
makewhatis是怎么样工作的呢?
[chengmo@centos5~]$manmakewhatis
#得到:
makewhatisreadsallthemanualpagescontainedinthegivensectionsofmanpathorthepreformattedpagescon-tainedinthegivensectionsofcatpath. Foreachpage,itwritesalineinthe whatis database; each lineconsists of the name ofthepageandashortdescription,separatedbyadash.Thedescriptionisextracted usingthecontentoftheNAMEsectionofthemanualpage.
#大概意思是:makewhatis从手册页配置的路径以及领域范围,搜集所有手册页索引信息,每个手册页在数据库加入一行,这行会包括手册页里面name,以及简单描述。
收获:知道这个数据库是建立是索引,并且每个数据库写入一行(aline),会不会这个数据库就是文本文件呢?现在到这里,我们不知道数据库保存地方,也不知道它结构,只有看看whatis命令,看它是不是有源码信息
怎么得到whatis程序源码?
[chengmo@centos5~]$typewhatis
whatisis/usr/bin/whatis
#告诉路径我们看看内容
[chengmo@centos5~]$vi/usr/bin/whatis
1#!/bin/sh
2#
3#apropos--searchthewhatisdatabaseforkeywords.
4#whatis --idem,butmatchonlycommands(aswholewords).
……
#它是个sh脚本,
#得到:
#grep“关键词“/var/cache/man/whatis
#它实际在查找这个文件,/var/cache/man/whatis就是上面说的whatis数据库
[chengmo@centos5~]$head/var/cache/man/whatis
$notes_name[Module::Build::Notes](3pm) -Configurationfor$module_name
*_unlocked[unlocked_stdio](3) -non-lockingstdiofunctions
#whatis数据库就是一个文本文件记录手册页的索引信息
whatis数据库是什么时候创建的呢?
[chengmo@centos5~]$ls-al/var/cache/man/whatis
-rw-r--r--1rootroot105715610-2704: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****rootrun-parts/etc/cron.hourly
024***rootrun-parts/etc/cron.daily
224**0rootrun-parts/etc/cron.weekly
4241**rootrun-parts/etc/cron.monthly
有run-parts脚本运行/etc/cron.daily目录下面的文件
[chengmo@centos5~]$cd/etc/cron.daily/
[chengmo@centos5cron.daily]$catmakewhatis.cron
#!/bin/bash
LOCKFILE=/var/lock/makewhatis.lock
makewhatis-u-w
……
找到了这个是由这个脚本运行的
以上是通过man命令查找帮助信息的一个过程,有问题,首先分析帮助是个不错的选择。
作者:chengmoQQ:8292669