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

所属分类: 脚本专栏 / linux shell 阅读数: 1837
收藏 0 赞 0 分享

通过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脚本中计算字符串长度的5种方法

这篇文章主要介绍了Shell脚本中计算字符串长度的5种方法,来自于个人Shell脚本长期的开发经验,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell脚本实现把进程负载均衡到多核CPU中

这篇文章主要介绍了Shell脚本实现把进程负载均衡到多核CPU中,可以把进程指定运行在某个CPU中,需要的朋友可以参考下
收藏 0 赞 0 分享

5个Shell脚本编程入门练习例子

这篇文章主要介绍了5个Shell脚本编程入门例子,涵盖了各种操作,又有一些游戏的性质,作为入门练习例子是不很不错的,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell脚本编程中常用的数学运算实例

这篇文章主要介绍了Shell脚本编程中常用的数学运算实例,包含最基本的加减乘除,还有质数、偶数的判断等,需要的朋友可以参考下
收藏 0 赞 0 分享

5个实用的shell脚本面试题和答案

这篇文章主要介绍了5个实用的shell脚本面试题和答案,给出的脚本堪称编码规范,麻雀虽小,异常处理,友好提示,一应俱全,值得学习,需要的朋友可以参考下
收藏 0 赞 0 分享

使用bash shell删除目录中的特定文件的3种方法

这篇文章主要介绍了使用bash shell删除目录中的特定文件的3种方法,分别为扩展模式匹配符、GLOBIGNORE 变量和find 命令,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell获取文件的文件名和扩展名的例子

这篇文章主要介绍了Shell获取文件的文件名和扩展名的例子,简明版的代码实例,看了就懂,需要的朋友可以参考下
收藏 0 赞 0 分享

Shell多线程操作及线程数控制实例

这篇文章主要介绍了Shell多线程操作及线程数控制实例,文中从单线程实现一个需求开始,不断加入代码实现多线程以及线程数的控制功能,需要的朋友可以参考下
收藏 0 赞 0 分享

阿里云主机一键安装lamp、lnmp环境的shell脚本分享

这篇文章主要介绍了阿里云主机一键安装lamp、lnmp环境的shell脚本分享,需要的朋友可以参考下
收藏 0 赞 0 分享

shell脚本转发80端口数据包给Node.js服务器

开发基于Node.js的WEB应用很方便,但是服务端口问题很蛋疼,由于Linux内核规定普通用户只能使用大于1024的端口号,所以使用普通用户运行Node.js服务就不能监听80端口
收藏 0 赞 0 分享
查看更多