In this guide, we will demonstrate how to use the “help” command in Linux.
Prerequisites:
To perform the steps that are demonstrated in this guide, you need the following components:
- A functional Linux system. For testing and learning purposes, a Linux VM will work fine.
- Basic understanding of the command-line interface
The Help Command
When working with CLI, we’re basically interacting with a shell program that acts as an interface to the underlying operating system. As of now, Bash is the most widely used shell program. Most Linux systems nowadays use Bash as the default shell.
The “help” command is a built-in shell command of Bash. It’s used to browse the shell documentation of other built-in commands like echo, cd, pwd, alias, and others.
To get a list of all the available documentation, run the “help” command by itself:
All the commands (and keywords) in the list are shell built-in commands and functions. We can verify it using the “type” command. For example:
The help documentation can be a brief summary or a relatively detailed one. However, for the full documentation, refer to the man pages (if available).
Basic Usage
In the following example, help will present a quick documentation of the “pwd” command:
Similarly, we can use “help” to check a quick documentation of other tools.
We can also take a quick look at the documentation of the “help” command itself:
Short Description
Instead of the documentation, “help” can print a brief description of the specified command. To do so, you have to add the “-d” flag:
In the first example, check out the short description of “pwd”:
Similarly, we can check the short description of other commands:
Pseudo Man Page
We can instruct “help” to print the documentation in the man page format instead. Since it’s not the actual man page of the command, it’s referred to as a pseudo man page.
To get the documentation in the man page format, use the “-m” flag:
For example, check out the help documentation of “help” in the man page format:
Similarly, we can apply this formatting to another documentation:
Command Syntax Only
Need a quick peek at the command structure of a specific command? Using the “-s” flag will display only the command syntax:
For example, to check the command syntax of echo, use the following command:
Similarly, we can check the command syntax of other commands:
Exit Codes
Depending on the success of the comment that is run, the “help” command returns an exit code. The exit code values are as follows:
- 0: The command runs successfully.
- 1: The given argument isn’t found.
- 2: Wrong option.
The following example demonstrates these exit codes:
$ echo $?
$ echo $?
$ echo $?
Conclusion
In this guide, we successfully demonstrated how to use the “help” command in Linux. It’s a shell built-in command that presents the documentation about other shell built-in commands.
Interested in learning more about the Linux shell? Check out about Bash scripting, a robust way of leveraging the Bash shell to automate the tasks.
Happy computing!