Datasheet

Book VIII
Chapter 1
. . . And UNIX
Lurks Beneath
649
Working with Files
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
will always take 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
operation. When you execute the command, the command line asks you for
a password. If you don’t know what the password is, you probably shouldn’t
be using sudo. Your computer’s administrator should have given you an
appropriate password to use. After you enter the correct password, the
command executes as desired.
In case you’re curious, sudo stands for set user and do. It sets the user to the
one that you specify and performs the command that follows the username.
sudo cp ~/Desktop/MyDocument /Users/fuadramses/Desktop/MyDocument
Password:
54_435410-bk08ch01.indd 64954_435410-bk08ch01.indd 649 8/6/09 12:44:59 AM8/6/09 12:44:59 AM