Distributed Networks Home
DBWebApplications eWebProgrammer
prev next prev next
  Course navigation
 
Lesson 3
Objective
Copying directories
Use cp -r command to copy directories.
   
You should already know the following about the cp command:
cp files directorycp -i old new
Command form Result
cp oldfile newfile Copy one existing file to a new name.
cp files directory Copy files to another directory.
cp -i old new Ask first before overwriting any file.
This lesson introduces the -r option, which lets you copy a directory into another directory. The general form is: % cp -r files directory You must use this command form if any of the specified files is a directory. Suppose you try to copy the images directory into the project directory, without using -r. Note that the following command fails: % cp images project
cp: images: is a directory However, with the -r option, cp recursively copies (subdirectory by subdirectory) the images directory tree into the project directory: % cp -r images project

As with any copy operation, you might overwrite the files in the destination area if the target files have the same names as what you are copying. Use the -i option to guard against this.

In the next lesson, directions on how to remove a directory tree by using the rm command will be given.
  Course navigation