How to Use the help Command in Linux

This tutorial explains what the help command is and how it is used to get help about the built-in commands in Linux. Learn how to use the help command through practical examples.

A Linux shell contains two types of commands: internal commands and external commands.

Internal commands are also known as the built-in commands. They are automatically installed as part of the shell when the shell is installed. Since internal commands are installed as part of the shell, most of them don't install any separate documentation.

To get information about these commands, we have to rely on the shell's documentation. If we want some information about an internal command such as the command syntax or available options, we have to read the entire shell document.

To get information about a single internal command, reading the entire shell document is not only a time-consuming process but also a tedious task. Luckily, shell offers a command, known as the help command, which not only makes this task easier but also completes this process as soon as we hit the Enter key.

What is the help command?

The help command is a shell built-in internal command. It accepts a text string as the command line argument and searches the supplied string in the shell's documents. If the supplied string matches with an internal command, the help command picks the available information about that command from the shell's document and displays that information on the terminal.

The help command syntax and options

The help command uses the following syntax.

$help [options] [text-string/pattern/internal-command]

The help command accepts three options: d, m, and s.

d: - If we use this option, instead of displaying all available information, the help command displays only a brief description of the specified command.

m: - If we use this option, the help command organizes the available information just as the man command does. We will learn about the man command in the next part of this article.

s: - If we use this option, the help command displays the command syntax of the specified command.

The help command examples

To view all available information about the cd command, specify the string 'cd' as an argument of the help command.

#help cd

The following image shows the output of this command.

help command without any option

To view all available information of the cd command as the man command displays, use the -m option.

#help -m cd

The following image displays this command with the output.

help command with m option

If you compare the output of this command with the output of the previous command, you can easily spot the differences between both outputs. Without the -m option, the help command displayed information in a simple text format, but when we used the -m option, the help command displayed information in sections. The man command organizes information in sections.

Instead of full description, if you only want to know what the cd command does, you can use the -d option.

#help -d cd

The following image shows the above command with the output.

help command with d option

The help command, when used with the -d option, provides a one-liner brief description of the specified command.

To view how to use the cd command or the command syntax of the cd command, specify the s option with the help command.

#help -s cd

The following image shows the output of the above command.

help command with s option

Can we use the help command to get help about the external commands?

No, the help command provides information only about the internal commands. To verify this, you can view the available information about the help command from the following command.

#help help

Since the help command itself is a built-in shell command, if we specify the help keyword as the argument, the help command displays information about itself.

The following image shows the output of the above command.

help command syntax and options

If you specify an external command as the argument, the help command displays the following generic message.

bash: help: no help topics match '[specified string]'. Try 'help help' or 'man -k [specified string]' or 'info [specified string]'.
  

For example, if you use the help command to get information about the passwd command, you will get the following error message.

bash: help: no help topics match 'passwd'. Try 'help help' or 'man -k passwd' or 'info passwd'.
  

The following image shows the error message you may receive if you specify an external command as an argument to the help command.

using help command on external commands

To figure out whether a command is an internal command or an external command, we can use the which command.

The which command prints the location from where the specified command executes.

As we know, internal commands are part of the shell and execute directly from the shell. Therefore, if the specified command is an internal command, the which command will not display any output.

If the specified command is an external command, the which command will display the location from where the specified command executes.

The following image shows an example of both types of commands.

knowing command type

Alternatively, you can use the following command to view all available internal commands.

#compgen -b | column

The following image shows a sample output of this command.

listing all internal commands

Getting help about external commands

External commands are part of the packages. They are installed when their respective packages are installed. Usually, when a package installs an external command, it also installs a detailed document about that command.

In the next part of this tutorial, we will understand what information a document page of an external command contains and what command-line tools are available to read information from the document pages of external commands.

That's all for this tutorial. If you like this tutorial, please don't forget to share it with friends through your favorite social network.

Advertisements

ComputerNetworkingNotes Linux Tutorials How to Use the help Command in Linux