Getting Help in Command Line Interface
Shivm Soaini
Math Major Turned AI Enthusiast: Mastering Computer Vision | Building Robust Python Code | Delving Deep into the Math of AI | Sharing Knowledge Through Writing | Ready to Transform Ideas into Reality
Sometimes it's difficult to wrap our head around some of the commands we encounter. In this scenario, man pages can come in handy.
The man pages, short for manual pages, are a built-in form of documentation available on nearly all UNIX-like operating systems.
The specific contents may vary from one operating system to another, but at a bare minimum the man pages include information on commands and their usage.
To read the specific piece of documentation associated with a given command, run man command
For example, to learn more about the ncal command we could run man ncal
This displays a bunch of information on ncal that we can scroll through.
Type "q" to exit.
Navigation and Search
If you want to scroll through the man page document, use can use downward arrow to move through one line at a time, or you can use space bar to move one page at a time, to go back to the previous page, use b key.
To search a particular option of command in the man page document, use forward slash (/) followed the option you want to know about.
In the example below, you can see the usage w.r.t the -w option of ncal command.
The details regarding our option are highlighted after our /-w command in the man page.
The anatomy of a man page
In general, each man page will follow this pattern:
- The title or name of the command with a short explanation of its purpose
- Synopsis of the command's syntax
- Description of the all the command's options
Try running man echo command, and you'll see the pattern mentioned above,
man page synopsis
ncal [-31bhJeoSM] [-A number] [-B number] [-d yyyy-mm] [year]
Anything listed inside of square brackets is OPTIONAL. The only required part is ncal.
The above synopsis for ncal tells us that we can use the following options without providing any sort of additional parameter: -3, -1, -b, -h, -J, -e, -o, -S, and -M.
To keep things brief, they are all lumped together as "-31bhJeoSM".
Then, we see other options in square brackets followed by their expected parameters:
领英推荐
"-A number" means the -A option expects a number.
"-d yyyy-mm" indicates that -d option expects us to pass in a date in the format yyyy-mm like 1980
Finally, at the end we see "year" which means that we can pass a year as a parameter.
Let's try another one.
echo [OPTION]... [STRING]...
The above synopsis is for the echo command, which echoes text back at us.
An ellipsis (...) indicates that one or more of the proceeding operand are allowed:
[OPTION]... means that we can pass more than one option to echo
[STRING]... indicates that we can pass multiple strings to echo. For example, we can run echo hello and also echo hello there you cute little puppy.
cp (copy) command synopsis
cp [OPTION]... SOURCE DEST
So far, all of the operands we've seen have been optional, but some commands do require certain arguments in order to run. In a man page synopsis, required operands are not wrapped in square brackets.
In the above synopsis for the copy (cp) command, we see that we can optionally provide one or more options. SOURCE indicates that we must pass one source, and DEST indicates that we must pass a destination as well. Those two arguments are required.
Types of commands
There are really four types of commands:
type command
The type command will tell us... the type of a command.
To find the exact location of an executable, run which command
This only works for executable(s), not built-in shell commands or aliases.
Getting Help with help
Some commands do not have man pages written for them, because they are commands that are directly built into the shell.
We can find documentation of those commands using the help command.
For example, to learn more about the cd (change current working directory) command, we would run help cd.