Datasheet

Book VIII
Chapter 1
. . . And UNIX Lurks
Beneath
685
Working with Files
Here’s a faster way. Instead of moving through each successive folder until
you reach your intended destination, you can specify the path by using just
one cd command:
WHITEDRAGON:/ markchambers$ cd /Users/markchambers
WHITEDRAGON:~ markchambers$
Of course, the Home directory is a special folder in that you can also navi-
gate there by simply entering cd ~, but the main point here is that you can
navigate directly to specific folders by using that folder’s path in conjunc-
tion with the cd command.
Furthermore, when you navigate your hard drive by using paths, you can
jump directly to your desired destination from any place. When you enter
cd .., it is in relation to your current position, whereas entering
cd /Users/markchambers
always takes you to the same directory, regardless of your starting point.
Copying, moving, renaming, and deleting files
After you’re comfortable with moving around the hierarchy of your hard
drive, it’s a cinch to copy, move, and rename files and folders.
To copy files from the command line, use the cp command. Because using
the cp command will copy a file from one place to another, it requires two
operands: first the source and then the destination. For instance, to copy a
file from your Home folder to your Documents folder, use the cp command
like this:
cp ~/MyDocument ~/Desktop/MyDocument
Keep in mind that when you copy files, you must have proper permissions
to do so! Here’s what happens when I try to copy a file from my Desktop to
another user’s Desktop (strangely named fuadramses):
WHITEDRAGON:~ markchambers$ cp ~/Desktop/MyDocument/Users/fuadramses/Desktop/
MyDocument
Denied! Thwarted! Refused!
cp: /Users/fuadramses/Desktop/MyDocument: Permission denied
If you can’t copy to the destination that you desire, you need to precede the
cp command with sudo. Using the sudo command allows you to perform
functions as another user. The idea here is that the other user whom you’re
“emulating” has the necessary privileges to execute the desired copy opera-
tion. When you execute the command, the command line asks you for a
55_9781118022061-bk08ch01.indd 68555_9781118022061-bk08ch01.indd 685 8/10/11 9:39 AM8/10/11 9:39 AM