Datasheet

Book VIII
Chapter 1
. . . And UNIX
Lurks Beneath
645
UNIX Commands 101
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/
Command-line gotchas
In earlier sections, I describe a few simple command-line functions. All these
commands have something in common: You might not have noticed, but
every example thus far involved folder names and filenames that contained
only alphanumeric characters. Remember what happens if you have a folder
name that has a space in it? Try the following example, but don’t worry
when it doesn’t work.
The cd command stands for change directory.
cd /Desktop Folder
The result is an error message:
-bash: cd: /Desktop: No such file or directory
The problem is that a space character isn’t allowed in a path. To get around
this problem, simply enclose the path in double quotation marks, like this:
cd “/Desktop Folder”
Mac OS X lets you use either double or single quotation marks to enclose a
path with spaces in it. Standard UNIX operating systems, however, use
double quotation marks for this purpose.
54_435410-bk08ch01.indd 64554_435410-bk08ch01.indd 645 8/6/09 12:44:59 AM8/6/09 12:44:59 AM