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
- The help option, written with two dashes, prints a short summary of a command's options.
- The whatis command prints one line saying what a program is for.
- The man command opens the full manual page, with every option explained.
- Press q to leave the manual reader.
- Ask the command before you guess at an option, because a wrong guess can change files.
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.
ls --helpNote: 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.
whatis lsWhen you need the details, open the full manual. The man command explains every option, with examples.
man lsNote: 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.
Print the usage line and the short list of options for ls.
ls --helpWhat you should see: The shell prints Usage: ls [OPTION]... [FILE]..., then the list of options.
Ask for the one-line reminder of what ls is for.
whatis lsWhat you should see: The shell prints one line: list directory contents.
Open the full manual page for ls, with every option explained.
man lsWhat 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.