Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 See this if you're having trouble printing code examples


Unix Power Tools
Copying Directory Trees with cp -r

by Jerry Peek
02/03/2000

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.

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: