The “help” Command in Linux [3 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The “help” is a built-in command tool that displays information regarding the existing built-in commands of the Linux shell. It is particularly useful to get information from the shell’s internal documentation. The command accepts text strings as arguments and searches for the provided arguments in the shell’s documents, saving you time from going through the entire document every time.

In this article, you will learn about the “help” command, and how to use it properly with practical examples.

Syntax of “help” Command in Linux

The best way of learning a command is to start by understanding its syntax. So, here is the basic syntax of the “help” command:

help [options] [pattern]
EXPLANATION
  • The [options] modifies the default behavior of the help command.
  • The [pattern] specifies a help topic.

Options of “help” Command in Linux

Here is the list of the few options available of the “help” command to modify the behavior of the command:

Option Function
-d Prints short descriptions for each topic.
-m Shows usage in pseudo-manpage format.
-s Outputs only a short usage synopsis for each topic matching.

How to Use “help” Command in Linux?

To use the help command for getting information about a command, just type the help command followed by the command you want the information for. For example, to see the info for the pwd command, just type the following command on your terminal and press ENTER:

help pwd

Getting help with pwd command using help command

OUTPUT ANALYSIS

Thus, the command shows all the available information about the specified “pwd” command as shown in the above image. Among these info includes:

  • A short usage syntax of the specified command.
    • Shows available [options] in the syntax;
    • arg_name for a required, singular argument;
    • [arg_name] for an optional, singular argument;
  • A short description of what the function does.
  • A well-formatted list of options each having a short description.
  • An exit status that holds the success or failure information about the outcome of a command’s execution.
  • Brief indicator of the location of config files or environment variables that might be the source of command line arguments.

3 Examples of Using “help” Command in Linux

In this section, you will learn a few examples of using the “help” command in Linux. Typically the “help” command provides a detailed description of the specified command. However, you can also customize your output as needed using the examples below:

1. Displaying Short Description of Shell Built-in Commands

To display a one-liner short description (like a TL;DR) of a command’s functionality, use the help command followed by the -d option.

In the prompt, enter the ‘help’ command followed by the command (for example: pwd) you wish to  see a short description for:

help -d pwd

Using help with -d option to print short description of a specified command

As a result, you can visualize what the specified command does.

2. Viewing Short Usage Synopsis of Shell Built-in Commands

To view the short usage synopsis of a command, you can use the help command with the -s option. This is particularly helpful if you are unsure how to use a certain command in different cases. For example to see the syntax of the pwd command:

help -s pwd

Using help with -s to view syntax of a command

Upon running, the command displays all the available options of the pwd command.

3. Viewing Command Information in Pseudo-Manpage Format

To get information about a command in a pseudo-manpage manner, use help with the -m option. It is helpful if you want to see the detailed explanation of a command in an organized manpage format.

For instance, run the command below to see the pseudo-manpage format of the pwd command:

help -m pwd

Displaying manpage format of help output using help command with -m option

With the -m option, the command formats the help command output as pseudo-manpage format to enhance readability.

Advanced Use Cases of “help” Command in Linux

Now, let’s see some more advanced use cases of the “help” command in Linux to dive deeper into the command:

1. Showing Manpages of Commands Starting with a Specific Letter

To list all available commands starting with a specific letter in a manpage style, use the help command with wildcard characters. Here is an example of showing all available commands starting with “h”:

help -m h*

Showing manpages of commands starting with h

As you can see, the command shows manpage style “help” for all available commands starting with ‘h’.

Note: In the above image, you can see one command because of the cropped image, but all the commands are displayed starting with “h”.

2. Listing Commands with Matching Patterns

To list commands that follow a given matching pattern, use the below command:

help -d 'h[ae]*'

Listing commands with matching patterns

This command lists all the available commands that start with “ha” or “he”.

Getting Help for the External Commands

In the Linux shell, there are two types of commands: built-in internal commands and external commands. To get help with the internal commands, you can use the help command. However, the “help” command does not provide information about the external commands. You can verify this by typing the below command:

help ls

Using help with external ls command in Linux

As you can see, the “help” command returns the above generic or error message when used with an external command like ls command as an argument.

To view information for external commands, you can use the man or info commands. For example, run the command below to get help for an external command ls:

man ls

Using man command for external commands

Upon execution, the command returns detailed information about the “ls” command.

Note: To check if a command is an external or internal command, use the which command. For example:

which help
which ls

Here, the internal “help” command returns no output whereas the external “ls” command does.Using which command to check if a command is either internal or external

To view all the internal commands at once, use the command: compgen -b | column

Conclusion

To wrap up, the help command in Linux is the simplest way to know command information. Hopefully, you are now able to use the “help” command to clear things up whenever you’re confused about a command. Feel free to reach out for any further questions or suggestions through the comment box below.

People Also Ask

What is “help” Command in Linux?

The help command is a shell built-in internal command in Linux that provides detailed information about a specified command on the terminal. The help command, when run with the -d option, prints a one-liner short description of the specified command.

Can the help command provide help for the external commands?

No, the help command can not provide help information for the external commands. In that case, you can use the man or info commands.

What is the difference between external and internal Linux commands?

The difference between the external and internal Linux commands is that the internal commands are built directly into the shell like read or help. They’re faster because the shell doesn’t need to search for them. However, the external commands are separate programs stored in system directories, like ls or cp. The shell finds them using your system’s path.

What is the difference between “help” and “man” commands in Linux?

The “help” command is a built-in command that provides a basic summary of how to use built-in shell commands and keywords. The “man” command provides reference manuals for both built-in and external commands, configuration files, and other system elements. In Linux, the “man” command is typically the definitive help guide.

What’s the difference between “-h” and “- -help”?

The difference between the “-h” and “- -help” options is mostly historical. In the past, commands used “-h” for various purposes. Now, “- -help” is the standard way to display a program’s built-in help message. Many programs still accept “-h” as well, but “- -help” is clearer and more common.  If you’re unsure, try “- -help” first.

Is it possible to run “help” command in Linux within a C program?

No, it is not possible to run the “help” command directly within the C program. The system(3) in the C program uses your system’s shell interpreter (/bin/sh) to run commands, which does not include “help”. Instead, you can use system("bash -c help") that introduces the “help” command specifically to bash for running within a C program.

Rate this post
Avatar photo

Yousuf Shovon is a Linux Content Developer Executive (LCDE) at SOFTEKO. Previously, he worked for ExcelDemy, writing over 60+ articles on Excel. His goal is to write quality content for users to read and learn. In the future, he also wants to build various projects with LinuxSimply. He completed his graduation and post-graduation in Information Technology from Jahangirnagar University. Yousuf finds joy in solving diverse Linux-related problems to gain an all-around experience in Linux. Read Full Bio

Leave a Comment