Copying Directory Trees with cp -r

Some versions of cp have a -r (recursive) flag. It copies all the files in a directory tree - that is, all the files in a directory and its subdirectories.

NOTE: One of our UNIX systems has a cp without a -r option. But it also has an rcp () command that does have -r. rcp can copy to any machine, not just remote machines. When I need cp -r on that host, I use rcp -r.

The first argument(s) to cp -r can be directory(s)-or, if you name any file(s), they'll be copied just the way they would without the -r. The last argument should be a directory. So, you can use cp -r in two ways:

Those two methods are really doing the same thing. They're both copying the tail of the first pathname(s) to the end of the last pathname.

Some gotchas:

- JP