Demystifying the `whatis` Command in Linux
When you're getting started with Linux or even if you're an experienced user,
there will be times when you need to quickly understand what a particular
command does. The whatis
command in Linux serves this purpose by providing a
brief description of command-line programs, system calls, and library functions.
In this article, we will delve into the whatis
command, discussing its syntax,
options, and examples of how to use it.
Syntax
The basic syntax of the whatis
command is quite simple:
whatis [options] keyword
In this format, [options]
refers to optional flags you can use to alter the
behavior of whatis
, and keyword
is the name of the command, system call, or
function you wish to know more about.
Options Table
Option | Shorthand | Description |
---|---|---|
--regex | -r | Interpret keyword as a regular expression |
--wildcard | -w | Interpret keyword as a wildcard expression |
--long | -l | Do not trim output to fit terminal width |
--apropos | -a | Also search for approximate matches |
--case-insensitive | -i | Case-insensitive search |
Examples with Outcomes
Basic Usage
To quickly get an understanding of the ls
command, you can run:
Command:
whatis ls
Sample Output:
ls (1) - list directory contents
This output tells you that ls
is used to list directory contents and that it
falls under section 1 (general commands) of the manual.
Using --regex
Option
To find commands that contain the pattern ls
, you can use the --regex
option:
Command:
whatis -r "ls"
Sample Output:
ls (1) - list directory contents
vls (1) - ls-like utility for VIPTV streams
Using --apropos
Option
For example, let's say you want to find out about commands that have something
to do with listing (list
). Using the --apropos
option will find approximate
matches related to the keyword.
Command:
whatis --apropos list
Sample Output:
list (n) - Element of a list. Lists may be nested.
ls (1) - list directory contents
lscpu (1) - display information about the CPU architecture
lsattr (1) - list file attributes on a Linux second extended filesystem
...
In this example, --apropos
expanded the search to include commands and terms
related to 'list', including ls
, lscpu
, lsattr
, and even a term like '
list' from the Tcl programming language (as indicated by section 'n' for Tcl/Tk
commands).
This option makes whatis
a more flexible tool when you're exploring commands
but are not exactly sure what you're looking for.
Using --wildcard
Option
If you'd like to look for commands that start with 'ls', you can use a wildcard search:
Command:
whatis -w 'ls*'
Sample Output:
ls (1) - list directory contents
lsattr (1) - list file attributes on a Linux second extended filesystem
lscpu (1) - display information about the CPU architecture
...
Combining Multiple Options
You can also combine multiple options for a more nuanced search:
Command:
whatis -wi 'LS'
Sample Output:
ls (1) - list directory contents
Here we used the case-insensitive (-i
) option along with the wildcard (-w
)
option to find commands that start with 'ls' regardless of the case.
Conclusion
The whatis
command is an incredibly useful tool for quickly finding out what a
particular Linux command, system call, or library function does. Whether you're
a beginner learning the ropes or an advanced user looking for quick
reminders, whatis
can help you navigate Linux's vast array of commands more
efficiently. This guide aimed to provide a comprehensive look at whatis
,
covering its syntax, options, and practical examples, to get you started on
mastering this helpful command.
What Can You DO Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.