How to Use the help Command in Linux

Linux provides various options to get help on the command line. You can choose any of these based on your time and requirements. For example, you can read manual pages for detailed information about a command or use the help command to get a quick overview of the options used with the command.

A Linux shell contains two types of commands: internal and external.
Internal commands are known as the built-in commands. They are part of the shell. The shell's manual pages include information about them. Linux does not provide separate manual pages for them.
External commands are part of software packages. Packages include manual pages that provide detailed information about external commands. Each package has dedicated manual pages that contain information only about commands related to the package.

In other words, external commands have dedicated manual pages, while internal commands depend on the shell's manual pages. If you want information about an internal command, such as the command syntax or available options, you must read the shell's manual pages. Reading the shell's manual pages to get information about a single internal command is tedious and time-consuming. In that context, you can use the help command.

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 provided 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]

It accepts three options: d, m, and s.

d:- If you use this option, it briefly describes the specified command instead of displaying all available information.

m:- If you use this option, it organizes the available information just as the man command does.

s:- If you use this option, it 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 help command without an option

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

#help -m cd

the help command with the m option

If you compare the above command's output with the previous command's output, 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 used with the -m option, it showed information in sections. The man command organizes information in sections.

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

#help -d cd

the help command with the 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 help command with the s option

Can you use the help command to get help with 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

If you specify the help keyword as the argument, the help command displays information about itself.

the 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'.

using help command on external commands

You can use the which command to figure out whether a command is internal or external. It prints the location from where the specified command executes. Internal commands are part of the shell and execute directly from the shell. If the given command is internal, It does not display any output. If it is an external command, it prints the location from where it executes.

knowing command type

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

#compgen -b | column

listing all internal commands

This tutorial is part of the tutorial series 'Getting help on the command prompt on Linux'. Other parts of this series are the following.

Chapter 01  How to Use the help Command in Linux
Chapter 02  How to Use the man command in Linux
Chapter 03  How to use the info and pinfo commands in Linux

Conclusion

Linux shell provides two types of commands: internal and external. Internal commands are part of the shell. External commands are part of software packages. The help command provides help information about the internal commands.

ComputerNetworkingNotes Linux Tutorials How to Use the help Command in Linux

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com