Datasheet
12
Phase 1
Working on the Command Line
Copying Files
Linux’s file-copying command is cp (which is short for copy). In its most basic form, cp copies
a single file from one location to another:
# cp /etc/fstab /home/project7/
This command copies the /etc/fstab file to the /home/project7 directory; you’ll find
the copy there under the same name as the original. You can rename the copy as you make it
by specifying a filename along with the target directory:
# cp /etc/fstab /home/project7/sample-file
For clarity, I’ve shown the target directory alone with a trailing slash (/) in the first of these
examples. This indicates that project7 is a directory, not a file, and will result in an error
message if /home/project7 doesn’t exist. Linux will accept a directory name as a target with-
out a trailing slash, though. For instance, if /home/project7/sample-file were a directory,
the second command would copy /etc/fstab into that directory under the name fstab.
You can copy an entire directory tree by using one of the recursion options (-r and -R):
# cp -R /etc/X11/ /home/project7/
This command copies the entire contents of the /etc/X11 directory, including all its sub-
directories, to /home/project7. Using -r in place of -R is likely to result in the same behavior,
but some versions of cp produce subtly different effects for these two commands.
For information on other cp options, consult the man page for the command.
Removing Extraneous Files
Now that you’ve created the new project directory and placed some files in it, you may want
to do some housecleaning. For this task, you may want to first change into the directory in
which you want to operate so that you don’t need to type the complete path to each file:
# cd /home/project7/X11/
If you type ls, you’ll see a list of files and directories. Perhaps your project doesn’t need
access to the xorg.conf file; you can remove it with rm:
# rm xorg.conf
Be sure you type this command from within your copied directory tree
(/home/project7/X11). If you type this command from the original /etc/X11
directory, X is unlikely to work the next time you start it!
As with cp, you can use the -r or -R option to recursively delete an entire directory tree:
# rm -r mwm/
83484.book Page 12 Monday, September 18, 2006 8:58 AM










