Getting help on the command line

Video 101 of 140 in Virtualization Foundations, in the unit “The shell and the filesystem tree”. 2:41, with English and Hindi audio.

In the middle of a task, you may need one option of a command and forget its name. A guessed option can be wrong, or it can change more than you meant. Every standard Linux command can explain itself, so you only need to know where to ask. This article shows the help option, the whatis command and the man manual, and when each one is the right tool.

What you will learn

Ask the command instead of guessing

An engineer on a Harbor Point Logistics server needs one option from a command, and cannot remember its name. Harbor Point is a fictional logistics firm, used for training examples. Guessing options is slow, and a wrong guess can change something you did not mean to change. Good news: every standard Linux command ships with its own help.

The quick summary from the help option

The quick way is the help option, which is written with two dashes. It prints a usage line and a short summary of the options, and then the prompt comes back at once.

Print a short summary of the options for ls
ls --help

Note: The summary lists the options, one per line, so you can find the name you need.

The one-line reminder and the full manual

Sometimes you only need a reminder of what a program is for. The whatis command gives one line, and it is the fastest answer.

Print one line saying what ls is for
whatis ls

When you need the details, open the full manual. The man command explains every option, with examples.

Open the full manual page for ls
man ls

Note: The manual opens on the screen. Press q to quit the reader.

What a manual page is on other systems

A manual page is the built-in manual for one command. The man command opens it right on the screen. In Windows PowerShell, the equivalent is Get-Help, for its commands. The habit is the same: ask the machine before you guess.

Try it yourself

You need a Linux terminal. Ask the ls command how it works, using the three ways in this article, and compare how much each one prints.

  1. Print the usage line and the short list of options for ls.

    ls --help

    What you should see: The shell prints Usage: ls [OPTION]... [FILE]..., then the list of options.

  2. Ask for the one-line reminder of what ls is for.

    whatis ls

    What you should see: The shell prints one line: list directory contents.

  3. Open the full manual page for ls, with every option explained.

    man ls

    What you should see: The manual opens on screen. Press q to quit it and return to the prompt.

Terms

Manual page
The built-in manual for one command, opened with the man command and read on the screen.
Usage line
The short line at the top of a help summary that shows how to run the command.

Check yourself

What is the difference between --help and man?

--help prints a short summary of the options and returns you to the prompt. man opens the full manual, with explanations and examples, until you press q.

Which command gives a one-line reminder of what a program is for?

whatis. For example, whatis ls prints one line saying that ls lists directory contents.

Why should you ask the command instead of guessing an option?

A guessed option can be wrong, or it can change more than you meant. The command already knows its own options.

Previous: What is a shell?. Next: Absolute and relative paths.