Linux commands often have long lists of options they support, many of which are single-letter mnemonics. These can be tricky to learn and remember, but their redeeming feature is their reusability: common options are shared by different commands.
The following options are the most common and are widely available across several commands. Learn these, and you’ll gain a solid understanding of how to use many different programs, with consistent results.
--help and --version for Vital Information
One flag that almost all commands support, modern and old alike, is --help (-h or -? is often available) to show a brief chunk of non-interactive help text. This is usually referred to as “usage” because it includes a summary line showing you how to use the command, plus details of its options: what they do and how they work.
Some help output, like that from ls above, can be almost as comprehensive as the command’s man page!
--help is very well-supported on Ubuntu and other modern Linux systems. Modern tools like bat, rg (ripgrep), and ncdu support both the long form and -h for short. Most GNU tools also support --help, although commands like ls and cd do not support -h.
ls doesn’t use -h for help, but as a shorthand for --human-readable. This causes it to print file sizes like "1K" instead of "1024".
The --version (-V) option goes hand-in-hand with --help because it helps you find out about the program, and it’s usually supported where --help is. Traditionally, the --version option prints the version of the program you’re running it against; for example:
This lets you confirm you’re running the version you intend to, and can be useful for troubleshooting. The only problem with --version is how much the output can vary from one tool to the next. Many programs, like ncdu, top, and jq print a single line, in a format that can potentially be parsed:
Meanwhile, GNU programs such as find, mkdir, and sed display a detailed license and credits alongside the software version, across several lines of output. The record probably goes to Vim, which lists specific features and indicates whether or not they are included in that particular version, producing plenty of output in the process:
--help and --version aren’t always supported by commands, particularly older ones or ones that are shell builtins. Some commands support --help, but not -h. On macOS, however, many core commands support neither; man is your best alternative in these cases.
--all to Show All Results
The --all (-a) option is often available if a command works with files, but ignores some of them by default. The most common example is probably ls --all, which shows hidden files in addition to regular ones. The du command reports on directories by default, but --all causes it to report on regular files too.
The which program also supports a -a option, with a slightly different meaning. By default, the command reports the first path of a given command that occurs in your PATH variable:
However, using the -a option will cause it to report every matching program:
Some commands take this concept a step further, with complementary options. For example, ls also supports a --almost-all (-A) option which shows all hidden files except for the special . and .. entries.
--force to Authorize Destructive Behavior
Many commands that carry out potentially destructive actions will exercise caution in certain situations. For example, if you use rm to remove a write-protected file, the command will prompt you for confirmation:
However, you can use the --force (-f) option to force removal:
Now, the command doesn’t prompt for confirmation or even indicate that the file was write-protected; it just silently deletes it. Other file-related commands, like cp and mv, which may overwrite existing files, support a --force (-f) option that provides the same behavior.
It’s important to note that force doesn’t really mean “do everything possible to carry out this action;” it’s more like “be a bit less careful than you normally would be.” For example, cp -f will overrule any checks cp might make for existing files, but it won’t copy a non-readable file at all.
--recursive to Descend Into Subdirectories
Recursion is a fascinating subject, and one that can be quite hard to get your head around. But in the context of Linux commands, it’s a bit more straightforward, usually referring to whether a command descends into directories. For example, by default, ls will list files in a directory, but not subdirectories:
With the --recursive (-R) option, ls will also show the contents of any subdirectories it encounters:
Programs that are likely to be useful when applied to many files will often support a --recursive option. The rm command has a commonly-recognized form—rm -rf—that is very dangerous: it forcibly removes all files (including directories) recursively. grep’s --recursive option is very useful because it lets you perform a text search across any set of files. The command also supports both -r and -R as shorthand equivalents.
It’s important to note that this setting is “all or nothing.” For example, -R will cause ls to continue descending into subdirectories until it finds no more. This means your final listing can be much, much longer than a non-recursive one. Some commands may offer a way of limiting the depth of this recursion, but rm, grep, and ls typically do not.
The best way to limit depth when you’re working with files recursively is to use the find command. find is recursive by default, and it supports a --maxdepth option which limits the descent to a fixed number of directory levels.
--output to Specify an Alternative Filename
Some types of commands generate a file rather than writing to standard output. These commands usually recognize a need to change the filename they choose, so they support a --output (-o) option that lets you specify one. The classic example is a compiler, like gcc (for the C language):
gcc -o myprog program.c
This command compiles the source code in program.c and generates an executable binary named myprog. By default, the gcc compiler names its output file a.out. This can be fine for quick programs and local development, but for more complex programs, it’s normal to specify an alternative.
The df command, which reports file system space usage, uses --output for a different purpose: to change its output format.
--quiet for Less Output and --verbose for More
Many programs produce output that can be formatted in different ways, and one easy way to do so is to control the amount of output. The --quiet (-q) and --verbose (-v) options do just this, and they can be very useful for scripting or debugging.
grep uses --quiet (and the synonym --silent) to suppress all output, in which case it acts purely as a yes/no check for a regex match via its exit status. Other tools that support --quiet include sed, diff, and brew, the package manager.
The --verbose option is often used by compilers; gcc produces a lot of diagnostic information if you run it with --verbose:
curl usually outputs the response data from a URL, but the --verbose option adds connection details, and the headers of both response and request, giving a lower-level look at the transaction.
-v is often used as a shorthand for --version instead of --verbose, so be sure you know which your command supports.
--ignore-case to Handler Lowercase and Uppercase the Same
Any program that involves pattern-matching, like grep or diff, will have a default policy on how it handles lowercase and uppercase letters. That’s usually to treat case as important, so that "exit_status" and "EXIT_STATUS" are treated as two different words:
When you don’t care about case, reach for the --ignore-case option:
Other common commands that support a --ignore-case option include sort, uniq, and locate. Many options of the find program have case-insensitive versions, like -iname and -ipath.