Anatomy of a UNIX Command

UNIX commands can perform many amazing feats. The simplest form of a UNIX command is the command itself. Despite their vast abilities, all commands follow a similar structure:

command <optional flag(s)> <optional operand(s)>

You can expand your use of the ls command by appending various flags, which are settings that enable or disable optional features for the command. Most flags are preceded by a dash (-) and always follow the command. For instance, you can display the contents of a directory as a column of names (complete with file details) by tacking on a -l flag to the ls command.

ls -l

Besides flags, UNIX commands sometimes also have operands. An operand is something that is acted upon. For example, instead of just entering the ls command, which lists the current directory, you can add an operand to list a specific directory:

ls ~/Documents/myProject/

The tilde (~) denotes the user’s Home directory.

Sometimes a command can take multiple operands, as is the case when you copy a file. The two operands represent the source file and the destination of the file that you want to copy, separated by a space. The following example copies a text file from the Documents folder to the Desktop folder by using the cp command (short for copy).

cp ~/Documents/MyDocument ~/Desktop/MyDocument

You can also combine flags and operands in the same command. This example displays the contents of a specific folder in list format:

ls -l ~/Documents/myProject/

Dummies Insider

Sign up for insider news on books, authors, discounts and more content created just for you.