Datasheet

650
Working with Files
A close cousin to the cp (copy) command is the mv (move) command. As
you can probably guess, the mv command moves a folder or file from one
location to another. (I told you that all this character-based stuff would start
to make sense, didn’t I?) To demonstrate, this command moves MyDocument
from the Desktop folder to the current user’s Home folder:
mv ~/Desktop/MyDocument ~/MyDocument
Ah, but here’s the hidden surprise: The mv command also functions as
a rename command. For instance, to rename a file MyDocument on the
Desktop to MyNewDocument, do this:
mv ~/Desktop/MyDocument ~/Desktop/MyNewDocument
In this case, you can see that the mv command is really copying the original
file to the destination and then deleting the original. Because both folders in
this example reside in the same folder (~/Desktop/), it appears as though
the mv command has renamed the file.
Again, like the cp command, the mv command requires that you have
proper permissions for the action that you want to perform. Use the sudo
command to perform any commands that your current user (as displayed
in the prompt) isn’t allowed to execute. On UNIX systems, not all users are
necessarily equal. Some users can perform functions that others can’t. This
is handy for keeping your child’s mitts off important files on your computer.
It also creates a hurdle should you choose to work on files while using your
child’s restricted user account. The sudo command lets you temporarily
become another user — presumably one that has permission to perform
some function that the current user can’t.
What would file manipulation be without the ability to delete files? Never
fear; UNIX can delete anything that you throw at it. Use the rm (short for
remove) or rmdir (short for remove directory) command to delete a folder
or file. For example, to delete MyNewDocument from the Desktop folder,
execute the rm command like this:
rm ~/Desktop/MyNewDocument
Once again, deleting files and folders requires that you have permission
to do so. In other words, any time that you manipulate files with the com-
mand line, you’re required to have the proper permission. If your current
user lacks these permissions, using sudo helps. You should also check to
make sure that your target is correctly spelled and that no pesky spaces that
could wreak carnage are lurking in the command.
54_435410-bk08ch01.indd 65054_435410-bk08ch01.indd 650 8/6/09 12:44:59 AM8/6/09 12:44:59 AM