The whatis linux command

whatis is used to search in a case insensitive way, the mandb database, for the name of a command, a library function, or a system call… in order to display its description.

whatis only searches the database keys, and not the description associated with these keys.

bind -> "- 2 2 1557252946 0 A - - gz bind a name to a socket"
..
# The database, that whatis searches
# in, contains keys and values.
#    key -> value 
#  item name -> description
# key is the name of a user
# command, or of a system or a 
# library call...
# value, is the description,
# of this user command, or of
# this system, or library call. 
# value additionally contains, 
# the manual section, to which
# the item belongs. 
# whatis only searches the keys,
# and not the description. 

By default whatis will search all the manual sections , for the item name . The -s option can be used, followed by section numbers, separated by comma, to specify the sections to search in.

debian:~$ whatis random
# random is in section 7, 4, and 3.
random (7) - overview of interfaces for obtaining randomness
random (4) - kernel random number source devices
random (3) - random number generator


debian:~$ whatis -s 3,4 random
# search only sections 3 and 4 for 
# random
random (3) - random number generator
random (4) - kernel random number source devices


debian:~$ whatis -s 3 random
# search only section 3 for 
# random
random (3) - random number generator

The description of more than one item can be gotten.

debian:~$ whatis ls who
# get the description of 
# ls and who.
ls (1) - list directory contents
who (1) - show who is logged on

By default when using whatis, the match must be exact, so the provided token, and the item name must fully match. regular expression can be used, to instead search for a pattern, by using the -r option, and as such a partial match is allowed.

debian:~$ whatis who
# Only exact match.
who (1)              - show who is logged on

debian:~$ whatis -r who
# Partial match is allowed, 
# when using regular expression.
who (1)              - show who is logged on
whoami (1)           - print effective userid


debian:~$ whatis -r '^who$'
# The pattern to search for, starts 
# and ends with who.
who (1)              - show who is logged on
 

debian:~$ whatis -r 'who$' 'whoami$'
# Search for two patterns, that 
# start and end with who, or whoami .
who (1)              - show who is logged on
whoami (1)           - print effective userid        

Instead of pattern matching using regular expression, pattern matching can be achieved, by using shell style wildcards, as in the *, or ? shell wildcards. In this case a full match must occur, after wildcard expansion. The used pattern must be quoted, as not to have the wildcards expanded by the shell, if there is a matching file.

debian:~$ whatis -w who
# The -w option, means shell style
# wildcards matching.
# When using shell wildcards,
# an exact match must occur,
# after expansion. This is why
# whoami is not matched. 
who (1)              - show who is logged on

debian:~$ whatis -w 'who*'
# * expands to anything which 
# starts with who, so who and 
# whoami are matched
who (1)              - show who is logged on
whoami (1)           - print effective userid   


debian:~$ touch whoareu
# Create a whoareu file.

debian:~$ whatis -w who*
# Shell style wild card is used,
# who* is not quoted, hence the
# shell expands who, to whoareu
# and the pattern that whatis
# searches for, is whoareu, which
# must exactly match the database
# key. 
whoareu: nothing appropriate.

By default, results are truncated to the terminal width, if what is preferred is to view the results in full length, then the -l option can be used.

debian:~$ whatis -r -s 3,8 '[ps]time$'
# Search only sections 3 and 8 for 
# the pattern [ps]time$.
# The item name must end with e($), 
# and it must contain either stime 
# or ptime
strptime (3) - convert a string representation of time to a...
vcstime (8) - Show time in upper right hand corner of the ...


debian:~$ whatis -rl -s 3,8  '[ps]time$'
# by default whatis will truncate the 
# result to the terminal width,
# the -l option can be used to print 
# the results to their full width .
strptime (3) - convert a string representation of time to a time tm structure
vcstime (8) - Show time in upper right hand corner of the console screen