Getting Help in Command Line Interface

Getting Help in Command Line Interface

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:

  • An executable program, usually stored in /bin, /usr/bin, or /usr/local/bin. These are compiled binary files (hence bin).
  • A built-in shell command. These commands are part of the shell (bash in our case)
  • A shell function
  • An alias


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.



要查看或添加评论,请登录

Shivm Soaini的更多文章

  • Pipelines

    Pipelines

    Pipes are used to redirect a stream from one program to another program. We can take the output of one command and…

  • The Standard Streams and Redirection

    The Standard Streams and Redirection

    The three standard streams are communication channels between a computer program and its environment. They are:…

  • Working with Files

    Working with Files

    The cat command The cat command concatenates and prints the contents of files. cat filename will read the contents of…

  • The Shortcuts

    The Shortcuts

    We can speed up our command-line experience by taking advantage of the many built-in shortcuts. These shortcuts are…

  • Deleting, Moving and Copying

    Deleting, Moving and Copying

    The rm command We use the rm (remove) command to remove files from our machine. For example, rm app.

  • The Nano Text editor

    The Nano Text editor

    Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular…

  • Making Files and Folders

    Making Files and Folders

    The touch command To create a new file from the command line, use the touch command. Provide a filename, and that file…

  • Navigating the CLI Sea

    Navigating the CLI Sea

    The root directory The starting point for the file system is the root folder. We call it the root, but its actual…

  • First Step in Command Line

    First Step in Command Line

    Some Familiar Terms A Shell is a computer interface to an operating system which expose the OS's services to the human…

  • A Brief History of Linux

    A Brief History of Linux

    The world of operating systems has many residents, but they can be segregated into two tribes: The Microsoft NT…

社区洞察

其他会员也浏览了