Another use
for the cp command
is copying entire directories. When
combined with the
-r
(recursive) option the cp
command can be used to copy a directory and all of its' contents
to another directory. Without the -r
option, the files and subdirectories contained within a directory
are not copied.
Note:
You will receive an error message if the -r
option is not used when copying a populated directory.
Command
Format
cp
-r [i]
source_directory(s) destination_directory
Examples
The following
is an example of how to copy a directory and all of its files
to a new directory name in the current directory:
$ cd
$ pwd
/home/chuck
$ cp -r Pig_Pen muddy.puddles
$ ls muddy.puddles
Dirt
$
The following
is an example of how to copy a directory to another directory
that is not in the current directory
$ pwd
/home/chuck
$ ls -F
Pig_Pen/
$ cp -r Pig_Pen /home/Lucy
$ ls -F /home/Lucy
Snoopy/ dog.bowls/
Pig_Pen/
$