Summary

The command line can be a daunting place to hang out in, even if you’re familiar with a few commands. However, almost every Linux command can tell you how to use it—if you know how to ask.

What Does the Command Usage Tell Me?

Some Linux commands do something useful all on their own. For example, pwd prints the working directory:

Other commands need more information. Takermdir, the command to delete a directory; it needs to know which directory to delete. you’re able to also run rmdir in different modes. For example, to report each directory as it’s removed, run rmdir -v:

The linux pwd command run with no operands.

Linux calls everything after the command’s name an operand. Letters that begin with a “-” and words that start with “–” are called options and they usually alter the command’s behavior. Words after options are parameters that pass data to the command.

A command’s usage will tell you which options it supports and which parameters you can pass it. It also explains which of these are optional and how you can combine them.

The linux rmdir command with the -v option and two parameters.

How Do I See Usage for a Command?

The most reliable way of finding a command’s usage iswith the man command. Most commands will tell you their usage in a “SYNOPSIS” section at the top of their manual. Take the which command as an example:

Here, the usage reads:

Most commands will also tell you their usage on error, including if you run them incorrectly. Commands that require parameters to do something useful will usually give usage if you run them without any:

In this case,the grep commandprints its usage because it needs at least oneregular expression patternto take any useful action.

The linux manual page for the which command.

Finally, there are a few commands that take an action without any parameters but don’t have a man page, so neither of these approaches works. With luck, however, such a command will support a –help option so that you may see usage like this:

The cd command prints its usage on the first line of output when you call it with the “–help” option.

The linux grep command showing its usage.

Each command is different and even the same command can behave differently across systems. For example, mkdir will report its usage on macOS but you’ll need to run mkdir –help or man mkdir on Linux to view it.

An Explanation of Usage Syntax

Once you have a command’s usage, you’ll need to understand it. There are a few separate parts, and some symbols that explain how everything fits together. Commands can, in theory, explain their usage however they want, but these conventions are broadly observed, particularly by the most common commands.

Usage usually includes some, or all, of the following:

The linux cd command with the –help option showing usage.

Takethe GNU alias commandas an example. Its usage is:

This usage indicates that alias accepts one short option (p) and any number of name/value pairs. So you’re able to run it in any of these forms:

Meanwhile, usage for the BSD version of mkdir (as used by macOS) looks like this:

This usage shows that mkdir supports two standalone short options (p and v) and a short option, m, that requires an argument. The command requires at least one directory name, but can accept more than one. So these forms are all valid:

I’ll leave you with a parting note, though: Some modern GNU tools simplify their usage e.g. “ls [OPTION]… [FILE]…” In this form, you’ll need to read further into the manual to see exactly which options the command supports and how they work.