Datasheet

Book VIII
Chapter 1
. . . And UNIX
Lurks Beneath
643
Uncovering the Terminal
The complementary cd command (lowercase) — which incidentally stands
for change directory — opens any folder that you specify. It works much the
same as double-clicking a folder in the Finder: The difference is that following
the cd command, you don’t immediately see all the folder’s content.
However, the cd command requires a parameter (extra options or information
that appear after the command) so that your Mac knows which folder to open.
For example, to open the Documents folder that resides in your Home
directory, type cd Documents and press Return. When you do, you might
be surprised to see another prompt displayed immediately. So where are all
the files in the Documents folder? You must enter another command to see
what items are in the folder that you just opened. Type ls again to see the
contents of the Documents folder.
If you try to open a folder that has a space in its name, make sure to enclose
the folder’s name in quotation marks, like this:
cd “My Picture Folder”
Read more about using quotation marks in your commands in the upcoming
section “Command-line gotchas.”
To return to your Home folder in this example, enter a modified version of
the cd command:
cd ..
This causes your Mac to move back up the folder hierarchy one folder to
your Home directory. By using these three simple commands — ls, cd
foldername, and cd .. — you can traverse your entire hard drive.
After you successfully enter a command, you can recall it by pressing the
up-arrow key. Press the up-arrow key again to see the command prior to
that, and so forth. This is an extremely useful trick for retyping extra long file
paths.
Using the skills you already have
Just because the Terminal is text based doesn’t mean that it doesn’t act
like a good Macintosh citizen. All the usual Mac features that you know and
love are there for you to use. Copy and Paste functions work as you might
expect — but only at the prompt position.
Drag-and-drop is also at your disposal. After you play around with the
Terminal for a while, you’ll find yourself bored to tears typing the long
paths that represent the files on your hard drive. To automatically enter the
path of a file or folder to a command, simply drag it to the active Terminal
window, as shown in Figure 1-2. The file’s full path instantly appears at the
location of your cursor. (Thanks, Apple!)
54_435410-bk08ch01.indd 64354_435410-bk08ch01.indd 643 8/6/09 12:44:58 AM8/6/09 12:44:58 AM