Once the shell has processed all of its special characters, what remains typically consists of commands and the arguments to them. Most commands correspond to executable files somewhere on your system, although some—such as cd—are built into the shell. It's possible for you to have more than one executable file with the same name on your system. The shell uses the PATH environment variable to determine which version to use.

The value of PATH is a list of directories, separated by colons (:), in the order in which you want the shell to search for executables. To see the value of your PATH, type:

echo $PATH

You can put your current directory (.) in your PATH, but it can leave you vulnerable to Trojan horse programs. For example, if . is at the beginning of your PATH, the shell looks in the current directory first when trying to find a program. A malicious user could leave a program called ls in a directory as a trap for you to fall into.

If you want to have your current directory in your PATH, make sure that you put it after the directories that hold the common utilities.

If you want to know which version of a command the shell will choose, use the which command. For example:

$ which ls

You can use command-line options to get more information:

$ which -laf ls
-rwxrwxr-x  1 root      root         19272 May 03  2002 /bin/ls

If you try this for a command that's built into the shell, which can't find it:

$ which cd
which: no cd in /bin:/usr/bin:/opt/bin

The whence command displays what the command means to the shell, including any aliases in effect. For example, if you've created an alias for ls, the output might be:

$ whence ls
'ls -F'

Understanding command syntax

Whenever you look up a command in Utilities, you see a syntax statement that summarizes how you can use the command. For most commands, this statement consists of the following components:

The name of the command to be executed. This may be the name of an executable program, such as a utility, or it may be the name of a command built into the shell.
The specific behavior that you want to invoke for the command. Options typically consist of an alphanumeric character preceded by a hyphen (for example, -c). Some options take an argument (for example, -n number). If you specify an option that takes an argument, you must include its argument as well.
Data the command requires (for example, a filename). If a command lets you enter multiple operands, they're usually processed in the order you list them. Unlike options, operands aren't preceded by a hyphen (for example, less my_file).

The entries in Utilities use some special symbols to express the command syntax:

You can specify one or more instances of the previous element. For example, in the less utility syntax, the ellipsis after the operand file indicates that you can specify more than one file on the command line:
less myfile1 myfile2
[ ]
The enclosed item is optional.
You can use only one of the items (for example, -a|-f).

You don't actually type these symbols when you invoke the command. For instance, the syntax description for less is given as follows:

less [-[+]aBcCdeEfimMnNqQrsSuUw] [-b n] [-x n]
     [-[z] n] [-h n] [-j n] [-p pattern]
     [-y n] [-[oO] logfile] [-t tag]
     [-T tagsfile] [+ cmd] [file...]

You can combine multiple options that don't take an argument. The -aBcCdeEfimMnNqQrsSuUw notation is shorthand for -a -B -c -C -d and so on.

If an argument to a command starts with a hyphen, you can signal the end of the options by using a double hyphen:

ls -l -- -my_file

For more information, see Utility Conventions in Utilities.

Displaying online usage messages

You can look up detailed usage descriptions or you can display brief summaries of the syntax and options of commands and utilities. If you want a detailed description of a utility, see Utilities. But if you just want a quick reminder of the syntax and options, you can display the utility's online usage message by invoking the use command (it's similar to man in UNIX and Linux). For example, to display the message for more, type:

use more

If you request usage for a command, and the command either doesn't have an executable in the current path or doesn't contain usage message records, use displays an error message. For more information, see use in Utilities—or type use use.


By default, when you start a utility or other program, it runs at the same priority as its parent. (Actually, priorities aren't associated with a process, but with the process's threads.) You can determine the priority of a process's threads by looking at the output of the pidin (Process ID INformation) command. If you want to run something at a specific priority, use on , specifying the -p option.

Last modified: 2014-11-17

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus