Home COMSC-171 <- Prev Next ->

UNIX command syntax

Concept

The UNIX command processor, called a shell, is a Turing complete, imperative programming language optimized for interactive use. Learning a UNIX shell is therefore similar to learning a new programming language, except that a shell designed in the 1970s can hardly be described as new. A few UNIX commands are built into the shell but most are separate programs. The shells invoke external programs just like internal functions, so learning UNIX programs is a lot like learning new library functions.

Details

A UNIX command contains one or more words (separated by spaces or tabs) and usually ends with a newline character.

The first word is the name of the command. Like a verb, it tells the system what action to perform. In a GUI (Graphic User Interface) the action is usually found in a menu.

Most commands can accept options, which follow the command name and usually begin with a - character. Like adverbs, options tell the command more about how to perform the action. Options may or may not appear in a GUI, if present they're usually deep in a menu structure.

Most commands also accept arguments (paramaters), which follow the options. Like nouns, arguments tell the command what objects to act on or what values to apply. In a GUI objects are usually represented by icons and values are usually chosen from a list or typed in a box. Example:

mv -n foo bar
mv
command, move or rename
-n
option, noclobber (do not overwrite extisting files)
foo
argument (the name of the file to move or rename)
bar
another argument (the target directory or file name)

A UNIX command can also contain redirection operators after the arguments. By default the output of a command goes to the terminal screen. Examples:

ls /etc > foo
ls
command, lists the names of files in a directory
/etc
argument, name of the directory to list
> foo
redirects output to a file foo
ls /etc | less
| less
redirects output to the less command, which displays input one screen at a time