An argument, also called a command line argument, is a file name or other data that is provided to a command in order for the command to use it as an input. A command is an instruction telling a computer to do something, such as execute (i.e., run) a program.
Although this use of the word argument might sound odd at first, it has long been employed in computer programming and in mathematics, where it refers to an independent variable whose value determines the value of a function.
Arguments are entered on the command line in the console or terminal window after the command and any options. A console is an all-text display mode which occupies the entire display screen; a terminal window is an all-text window in a GUI (graphical user interface) that emulates a console. Each argument is separated by one or more spaces from adjacent arguments, options or the command.
That is, the three file names on the same line as wc are all inputs to it. wc reads the three files in the order that they have been written and then writes the number of lines, words and characters that it has found in each of them to standard output, which by default is the display screen.
An option, also sometimes referred to as a switch or a flag, is a single-letter code that modifies the behavior of a command in some predetermined way. In the case of multiple options, 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 usually preceded by a single hyphen, again with no intervening space.
wc has several options. Among them is -w, which tells it to count only the number of words. Another is -l, which tells it to count only the number of lines. These two options can be used together to count both the number of words and the number of lines for each of the three files in the above example, i.e.,
If an argument consists of two or more words separated by spaces, then it must be enclosed in quotes so that the system will know that it is a single argument instead of multiple arguments. Thus, the following can be used to count the numbers of words and lines in each of the two files called my file1 and my file2:
The same result is achieved using single quotes instead of double quotes, i.e.,
The efficiency of arguments can often be increased through the use of wildcards and other regular expressions. A wildcard is a character that is used to represent some category of character or characters in pattern matching. The wildcard with the broadest coverage and which is most commonly used is the asterisk ( * ), which stands for any combination of characters, including no characters. Its use eliminates the need to type in all the individual file names as arguments. Regular expressions are a powerful pattern matching technique that is widely used for searching for files and for data within files.
For example, to determine the total number of lines in all the html files (i.e., files that can produce web pages in a browser) in the current directory (i.e., the directory in which the user is currently working), the argument *.html can be used as follows:
The number of arguments that a command can have depends on the particular command. Some commands do not accept any arguments. Other do not require any arguments but can accept them. Still others require at least one argument, and some require multiple arguments.
The clear command, which is used to remove all previous commands and output from the display screen, is one of the very few commands in Unix-like operating systems that accepts neither options nor arguments. That is, it can only be used as follows:
pwd, which stands for present working directory and tells the user the name and location of the current directory, likewise does not accept any arguments. Rather, it receives its input from the shell (a program that reads commands that are typed into a computer system and then executes them). Moreover, it only has two very basic options, --help and --version. Thus, it is almost always used just as
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.
Other examples of commands that accept only options and no arguments include dmesg, which shows the messages produced by the kernel while a system is booting up (i.e., starting up), and ps, which shows the processes (i.e., instances of programs in execution) on the system.
Some commands, such as wc and cat, which is used to read and concatenate (i.e., combine) files, can have any number of arguments, including zero. In the event of zero arguments, these commands can receive input data from text typed in at the keyboard or from the output which is redirected from other commands via pipes.
The type of data acceptable for arguments varies according to the particular command. Most commonly it is file names. The arguments for the du command, which shows shows the sizes of files and directories, can be the names of files and/or directories. The apropos command, which searches for relevant topics in the man pages (i.e., the user manual that is built into most Unix-like operating systems) accepts all strings (i.e., sequences of characters) as argument(s), not just the names of files.
The arguments for the kill command, which is used to terminate malfunctioning processes, are process identification numbers (PIDs), which are automatically generated by the operating system and used by it to reference processes. The w command, which shows who is logged into the system and what they are doing, accepts only the names of users as arguments, although it is often used without any arguments.
Examples of commands that require multiple arguments are cp and move, each of which requires two, one for the name of the file to be copied or moved and one for the name of the copy or the destination.
Created June 15, 2004. Updated May 25, 2005.