Linux whatis and whatis database usage and query method (man usage example)

Time:2021-11-25

Find help through man:

[[email protected] ~]$ man -h

 f:same as whatis(1)

#I think it’s strange. What’s whatis?

[[email protected] ~]$ man whatis
#The query result is:
#whatis – search the whatis database for complete words.
#It is a tool for querying whatis database

#The whatis database is created using the command /usr/sbin/makewhatis.
#It also says that the whatis database is established through / usr / bin / makewhatis

Harvest: the whatis database is created by makewhatis, and the whatis script is used for query
 

How does makewhatis work?

[[email protected] ~]$ man makewhatis

#Get:

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 collects all man page index information from the man page configuration path and domain scope. Each man page adds a row in the database, which will include the name and brief description in the man page.

Harvest: if you know that the database is indexed and each database writes a line, will the database be a text file? Now here, we don’t know where the database is stored or its structure. We can only look at the whatis command to see if it has source code information
How to get the whatis program source code?

[[email protected] ~]$ type whatis
whatis is /usr/bin/whatis

#Tell us the path and let’s see the content

[[email protected] ~]$ 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).

……

#It’s an SH script,

#Get:

#Grep “keyword” / var / cache / man / Whatis

#It is actually looking for this file, / var / cache / man / whatis is the whatis database mentioned above

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

#Whatis database is a text file that records the index information of man pages

 

When was the whatis database created?

[[email protected] ~]$ ls -al /var/cache/man/whatis
-rw-r–r– 1 root root 1057156 10-27 04:06 /var/cache/man/whatis

#It was found that the creation time was around 4 a.m. after reading this, it was created by the system, so cron doubted it

 

[[email protected] ~]$ 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 the run parts script to run the files in the / etc / cron.daily directory

[[email protected] ~]$ cd /etc/cron.daily/

[[email protected] cron.daily]$ cat makewhatis.cron
#!/bin/bash

LOCKFILE=/var/lock/makewhatis.lock

makewhatis -u -w

……

Found this is run by this script

The above is a process of finding help information through the man command. If there is a problem, it is a good choice to analyze help first.

Author: Chengmo QQ: 8292669

Recommended Today

Apache sqoop

Source: dark horse big data 1.png From the standpoint of Apache, data flow can be divided into data import and export: Import: data import. RDBMS—–>Hadoop Export: data export. Hadoop—->RDBMS 1.2 sqoop installation The prerequisite for installing sqoop is that you already have a Java and Hadoop environment. Latest stable version: 1.4.6 Download the sqoop installation […]