The Parts of a Command

The first word you type on a line is the command you wish to run. In the "Getting Started" section we saw a call to the date command, which returned the current date and time.

Arguments

Another command we could use is echo, which displays the specified information back to the user. This isn't very useful if we don't actually specify information to display. Fortunately, we can add more information to a command to modify its behavior; this information consists of arguments . Luckily, the echo command doesn't argue back; it just repeats what we ask it:

$ echo foo
foo

In this case, the argument was foo, but there is no need to limit the number of arguments to one. Every word of the text entered, excluding the first word, will be considered an additional argument passed to the command. If we wanted echo to respond with multiple words, such as foo bar, we could give it multiple arguments:

$ echo foo bar
foo bar

Arguments are normally separated by "white space" (blanks and tabs -- things that show up white on paper). It doesn't matter how many spaces you type, so long as there is at least one. For instance, if you type:

$ echo foo              bar
foo bar

with a lot of spaces between the two arguments, the "extra" spaces are ignored, and the output shows the two arguments separated by a single space.

Options

Revisiting the date command, suppose you actually wanted the UTC date/time information displayed. For this, date provides the --utc option. Notice the two initial hyphens. These indicate arguments that a command checks when it starts and that control its behavior. The date command checks specially for the --utc option and says, "OK, I know you're asking for UTC time." This is different from arguments we invented, as when we issued echo with the arguments foo bar.

Other than the dashes preceding the word, --utc is entered just like any other argument:

$ date --utc
Tue Mar 24 18:12:44 UTC 2009

Usually, you can shorten these options to a shorter value such as date -u (The shorter version often has only one hyphen. Short options are quicker to type (use at shell), whereas long options are easier to read (use in scripts).

Now let's say we wanted to look at yesterday's date instead of today's. For this we would want to specify the --date argument, which takes an argument of its own. The argument for an option is simply the word following that option. In this case, the command would be date --date yesterday.

Since options are just arguments, you can combine options together to create more sophisticated behaviour. For instance, we could combined the previous two options to get the UTC information from yesterday you would type:

$ date --date yesterday -u
Mon Mar 23 18:16:58 UTC 2009

Repeating commands

Use the up arrow key to retrieve a command you issued before. You can move up and down using arrow keys to get earlier and later commands. The left arrow and right arrow keys let you move around inside a single command. Combined with the backspace key, these let you change parts of the command and turn it into a new one. Each time you press the Enter key, you submit the command to the terminal and it runs.