Using the `whatis` Command (with examples)

Using the `whatis` Command (with examples)

The whatis command is a useful tool for quickly getting one-line descriptions from manual pages in the terminal. It can be especially helpful when you want to quickly look up information about a specific command or find commands that match a specific pattern. In this article, we will explore different use cases of the whatis command and provide code examples to illustrate each one.

Viewing a Description for a Command

To view a description for a specific command, you can simply use the whatis command followed by the command name. This will display a one-line description from the corresponding manual page. Here is an example:

whatis ls

Motivation: This use case is helpful when you want to quickly understand what a particular command does without having to navigate through the full manual page.

Explanation: The whatis command is followed by the name of the command you want to look up. In this example, we are looking up the description for the ls command.

Example Output:

ls (1)               - list directory contents

Displaying Long Descriptions

By default, the whatis command cuts off the description at the end of the line to maintain readability. However, if you want to see the full description without truncation, you can use the --long option. Here is an example:

whatis --long grep

Motivation: This use case is useful when you want to obtain a more detailed and complete description of a command.

Explanation: The --long option is added to the whatis command to display the full description of the command. In this example, we are viewing the long description for the grep command.

Example Output:

grep (1)             - print lines matching a pattern

Searching with Wildcards

If you want to find descriptions for commands that match a specific pattern or use wildcards, you can use the --wildcard option with the whatis command. Here is an example:

whatis --wildcard net*

Motivation: This use case is handy when you want to search for commands related to a specific topic or that have a common prefix.

Explanation: The --wildcard option allows the use of wildcards in the command name. In this example, we are searching for command descriptions that start with “net”.

Example Output:

netkit-ftp (1)       - classic BSD FTP client
netkit-rsh (1)       - rsh, rlogin, rexec - remote login
netkit-rshd (8)      - rsh server
netkit-tftp (1)      - A TFTP client and server.
netsnmp_assert (3)   - assert infrastructure
netsnmp_assert_api (3) - assert infrastructure - api request id assertions
...

Searching with Regular Expressions

To search for command descriptions using regular expressions, you can use the --regex option with the whatis command. This allows for more advanced searches with pattern matching. Here is an example:

whatis --regex 'wish[0-9]\.[0-9]'

Motivation: This use case is beneficial when you want to search for commands that match a specific pattern using regular expressions.

Explanation: The --regex option enables the use of regular expressions to match command names. In this example, we are searching for command descriptions that match the pattern “wish[0-9].[0-9]”.

Example Output:

wish (1)             - Start a Wish (Tcl/Tk) interpreter
wish8.6 (1)          - Start a Wish (Tcl/Tk) interpreter

Displaying Descriptions in a Specific Language

If you have the manpage-locale package installed, you can use the --locale option with the whatis command to view command descriptions in a specific language. Here is an example:

whatis --locale=en ls

Motivation: This use case is useful when you want to view command descriptions in a language other than the default system language.

Explanation: The --locale option allows you to specify the language for displaying command descriptions. In this example, we are requesting the English (en) language descriptions for the ls command.

Example Output:

ls (1)               - list directory contents

In conclusion, the whatis command provides a quick way to retrieve one-line descriptions from manual pages. Whether you need a brief overview of a specific command or want to search for commands that match specific patterns, whatis can be a valuable tool in your command-line workflow.

Related Posts

How to use the command 'pypy' (with examples)

How to use the command 'pypy' (with examples)

This article provides examples of various use cases for the ‘pypy’ command, which is a fast and compliant alternative implementation of the Python language.

Read More
diff3 Examples (with examples)

diff3 Examples (with examples)

Use Case 1: Compare files The diff3 command is used to compare three files line by line.

Read More
How to use the command 'keep-header' (with examples)

How to use the command 'keep-header' (with examples)

The ‘keep-header’ command is a powerful tool in the tsv-utils package that allows users to manipulate files while keeping the first line intact.

Read More