LINFO

Option Definition



An option, also referred to as a flag or a switch, is a single-letter or full word that modifies the behavior of a command in some predetermined way.

A command is an instruction telling a computer to do something, usually to launch a program. The availability of options adds greatly to the flexibility and versatility of commands, and the availability of numerous commands each with an array of options adds greatly to the flexibility and power of Unix-like operating systems.

Options are distinct from arguments, which are input data provided to commands, most commonly the names of files and directories. Commands can also receive input data via pipes, which are a type of redirection that is designed to transfer the output of one command to be used as the input for another. Options can be used simultaneously with arguments and redirection.

Most commands have at least a few options, and some have numerous options. Multiple options generally can be used simultaneously.

Options are used on the command line (the all-text display mode) following the name of the command and before any arguments. They are separated from the name of the command and arguments by at least one space.

Most options are represented by a single letter. The letters are case sensitive (i.e., distinguish between lower case and upper case letters), as is almost everything in Unix-like operating systems. Although the use of lower case letters for options is more common, many commands use both upper and lower case letters in their repertories of single-letter options. Single letter options, or groups thereof, are almost always preceded directly (i.e., with no intervening space) by a single hyphen in order to inform the system that they are options, not arguments.

Most commands also have at least a few full-word options. The most common of these are --help and --version, which are found on most commands. Each full word option is always preceded directly by two consecutive hyphens.

Many commands also provide full word equivalents for their single-letter options. For example, the du (i.e., disk usage) command provides such choices for almost all of its options, such as -a and --all and -b and --bytes. The full word versions may be easier to remember for some people and are easier to read when used in shell scripts (i.e., small programs that incorporate commands and their options).

Some options are designed to accept arguments. For example, du's --max-depth= option is followed by an integer which tells du the number of layers in the directory hierarchy for which to report disk usage.

If multiple single-letter options are used simultaneously with the same command, all the letters are placed adjacent to each other (i.e., not separated by spaces) and can be in any order. The set of options is preceded by a single hyphen, again with no intervening space.

ps, which shows the processes (i.e., instances of programs in execution) on the system, is a rare example of a command for which it is not necessary to precede the single-letter options with a hyphen. This is apparently for historical reasons, and it is possible because ps does not accept any arguments, and thus there is no possibility of the system assuming that options without a hyphen are arguments. Thus, the following two commands produce identical results:

ps -aux

and

ps aux

The -a option tells ps to show the process state, the -u option tells it to show detailed information about the processes and the -x option tells it to show all processes.

clear, which removes all previous commands and their output from the display screen, is one of the very few commands in Unix-like operating systems that has no options. Making it even more unique is that fact that it also does not accept any arguments. That is, it is only used as follows:

clear

The whatis and apropos commands are also unusual in that they have no options. However, both not only have, but also require, at least one argument. whatis provides very brief descriptions of command line programs (i.e., all-text mode programs) and other topics related to Unix-like operating systems. apropos provides a list of all topics in the man pages (i.e., the standard user manual that is built into Unix-like operating systems) that are related to the subject of a query.

pwd, which stands for present working directory and tells the user the name and location of the current directory (i.e., the directory in which the user is currently working), is one of the few commands that has only two very basic options, i.e., --version (which tells what version is currently installed) and --help (which lists these two options and not much else). Although these options are listed on pwd's documentation, they do not appear to function on some systems (e.g., Red Hat Linux 9). pwd does not accept any arguments, and thus it is almost always used as just

pwd

Anything that is typed on the same line after pwd, with the exception of its options, is just ignored, and no error messages are returned.

Another example of a command that accepts only options and no arguments is dmesg, which shows the messages produced by the kernel (i.e., the core of the operating system) while a system is booting up (i.e., starting up).

There is some consistency of options among the various commands. For example, -a is often used to indicate all, -i is often used to add case insensitivity to a command and --version is commonly used to indicate the version number of the command installed. However, there are many exceptions, at least for the single-letter options. For example, with some commands -i is used instead to it interactive, as in the case of the rm command, which is used to remove files and directories.

Most options are available to any user of the command. However, some are restricted to just the root user (i.e., the administrative user) even if the command is available to all users. An example is the -c option for dmesg, which which clears the buffer (i.e., the section of memory that holds its data) after writing its output to the display screen (or wherever else it is directed).

The full list of options for any command can be obtained by consulting the appropriate page on the built-in manual. This can be accessed by entering the man command followed by the name of the command about which information is being sought. In many cases a large number of options will be shown, but usually only a small number of them are frequently used.






Created August 10, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.