In the last lesson, cp copied files. A directory needs one more thing.
cp skips directories
text
learner@tidepool:~/shop$ cp orders orders-copy
cp: -r not specified; omitting directory 'orders'cp copied nothing.
-r: the directory and everything under it
The flag -r copies the directory, then everything in it, then everything in those directories, to the bottom of the tree. This is a recursive copy. r stands for recursive.
text
learner@tidepool:~/shop$ cp -r orders orders-copy- shop
- orders
- monday.txt
- tuesday.txt
- orders-copy← new
- monday.txt
- tuesday.txt
Does the destination exist?
| Destination | Result of cp -r orders DEST |
|---|---|
| Does not exist | DEST is made, as a copy of orders |
| A directory that exists | The copy goes into it: DEST/orders |
Run ls on the destination before you copy, so that you know which row you get.