UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 18.14 Relinking Multiple Symbolic Links Chapter 18
Linking, Renaming, and Copying Files
Next: 18.16 Copying Directory Trees with (tar | tar)
 

18.15 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 (1.33) 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


Previous: 18.14 Relinking Multiple Symbolic Links UNIX Power ToolsNext: 18.16 Copying Directory Trees with (tar | tar)
18.14 Relinking Multiple Symbolic Links Book Index18.16 Copying Directory Trees with (tar | tar)

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System