Linux whatis Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn about the Linux whatis command and its practical applications. The whatis command is a utility that provides a brief description of a command or system component by searching the system's manual page database. You will explore the purpose, syntax, and options of the whatis command, as well as demonstrate its practical use cases. This lab is designed to help you quickly understand the purpose of various commands and system components without having to read through the entire manual page, making it particularly useful for new Linux users.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicSystemCommandsGroup -.-> linux/help("`Command Assistance`") linux/BasicSystemCommandsGroup -.-> linux/man("`Manual Access`") linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") linux/FileandDirectoryManagementGroup -.-> linux/which("`Command Locating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") subgraph Lab Skills linux/help -.-> lab-423005{{"`Linux whatis Command with Practical Examples`"}} linux/man -.-> lab-423005{{"`Linux whatis Command with Practical Examples`"}} linux/grep -.-> lab-423005{{"`Linux whatis Command with Practical Examples`"}} linux/which -.-> lab-423005{{"`Linux whatis Command with Practical Examples`"}} linux/ls -.-> lab-423005{{"`Linux whatis Command with Practical Examples`"}} end

Understand the Purpose of whatis Command

In this step, you will learn about the purpose of the whatis command in Linux. The whatis command is a utility that provides a brief description of a command or system component by searching the system's manual page database.

To begin, let's explore the basic usage of the whatis command:

whatis ls

Example output:

ls (1)           - list directory contents

As you can see, the whatis command displays a brief one-line description of the ls command, which is to list the contents of a directory.

The whatis command is particularly useful when you need to quickly understand the purpose of a command or system component without having to read through the entire manual page. It can be especially helpful for new Linux users who are not yet familiar with the various commands and utilities available on the system.

Explore the Syntax and Options of whatis Command

In this step, you will learn about the syntax and available options of the whatis command.

The basic syntax of the whatis command is:

whatis [options] keyword

Here are some common options for the whatis command:

  • -a or --appropos: Search for keywords in the manual page names and descriptions, instead of just the descriptions.
  • -n or --section: Specify the manual section to search, such as 1 for user commands, 5 for file formats, etc.
  • -r or --regex: Interpret the keyword as a regular expression.
  • -s or --sections: Specify a comma-separated list of manual sections to search.

Let's try some examples:

whatis -a grep

Example output:

grep (1)         - print lines matching a pattern
grep (1p)        - a pattern matching utility

The -a option allows whatis to search both the command name and description, returning more results.

whatis -n 5 passwd

Example output:

passwd (5)       - password file

The -n 5 option limits the search to only the file formats manual section.

whatis -r '^ls'

Example output:

ls (1)           - list directory contents

The -r option allows using a regular expression as the search keyword.

Demonstrate Practical Use Cases of whatis Command

In this final step, you will explore some practical use cases of the whatis command.

One common use case is to quickly find the purpose of a command or system component when you're unsure of its function. For example, let's say you encounter the du command and want to know what it does:

whatis du

Example output:

du (1)           - estimate file space usage

This tells you that the du command is used to estimate file space usage.

Another use case is to search for related commands or utilities when you know the general purpose, but not the specific command name. For instance, if you want to find commands related to managing user accounts, you can use the -a option:

whatis -a user

Example output:

adduser (8)      - add a new user or update default new user information
deluser (8)      - remove a user account and related files
usermod (8)      - modify a user account
useradd (8)      - create a new user or update default new user information
userdel (8)      - delete a user account

This gives you a list of commands related to user management, which can help you find the right tool for the task at hand.

Finally, the whatis command can be useful for quickly checking the manual section of a command or component. This is especially helpful when a command has the same name as a file format or system component. For example:

whatis -n 5 passwd

Example output:

passwd (5)       - password file

This shows that passwd has a manual page in section 5, which covers file formats, rather than the user command in section 1.

Summary

In this lab, you first learned about the purpose of the whatis command in Linux, which is to provide a brief description of a command or system component by searching the system's manual page database. You then explored the syntax and available options of the whatis command, such as the -a option to search both the command name and description, and the -n option to specify the manual section to search. These steps provided a solid understanding of how to effectively use the whatis command to quickly understand the purpose of various Linux commands and utilities.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like