The same cp notes.txt X can put the copy in three different places. Which one depends on what already goes by the name X.
cp copies a file. The first path is the source, what you copy. The last one is the destination, where it goes. The source stays put, and what happens to the destination depends on what already has that name:
What X is |
Result of cp notes.txt X |
|---|---|
| no such name | a new file X, a copy of notes.txt |
| a directory | a copy inside it: X/notes.txt |
| a file | the contents of X replaced, no questions asked |
A trailing slash on the destination works as a safeguard. cp notes.txt archive/ only works if archive is a directory. If it does not exist, cp fails with Not a directory and creates nothing.
With -i, cp asks before replacing a file: y replaces it, n keeps it. The -r option copies a directory with everything in it: cp -r config config.bak.
In the exercise you choose the commands.
Prepare a copy for handoff
In ~/file-lab, put a copy of source/site.conf into a new handoff/config directory under the same name. The original must stay where it is.
Goals · 0 of 2
- Create the handoff/config directory not done yet
- Copy site.conf there, leaving the original alone not done yet