Linux Commands

Linux Help Command

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:

$ help

 

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:

$ type help export test eval exec pwd return

 

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:

$ help pwd

 

Similarly, we can use “help” to check a quick documentation of other tools.

$ help su

 

$ help cd

 

$ help echo

 

We can also take a quick look at the documentation of the “help” command itself:

$ help help

 

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:

$ help -d <argument>

 

In the first example, check out the short description of “pwd”:

$ help -d pwd

 

Similarly, we can check the short description of other commands:

$ help -d su

 

$ help -d cd

 

$ help -d echo

 

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:

$ help -m <argument>

 

For example, check out the help documentation of “help” in the man page format:

$ help -m help

 

Similarly, we can apply this formatting to another documentation:

$ help -m su

 

$ help -m cd

 

$ help -m echo

 

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:

$ help -s <argument>

 

For example, to check the command syntax of echo, use the following command:

$ help -s echo

 

Similarly, we can check the command syntax of other commands:

$ help -s su

 

$ help -s cd

 

$ help -s help

 

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:

$ help help

$ echo $?

 

$ help adsf

$ echo $?

 

$ help -asdf

$ 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!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.