Files & folders · Copy and move
Copy a file: cp
cp (copy) makes a copy of a file. The original stays as it is.
Why: to keep a backup before you change something, or to start a new file from an old one.
How to type it: cp source copy: first the file you have, then the name of the copy.
Worked example
learner@shellstreak:~$ cp notes.txt notes-copy.txtWhat happened
- No output.
notes-copy.txtnow exists, with exactly the same lines asnotes.txt;cat notes-copy.txtshows them.
Common mistakes
- Swapping the order. The source comes first:
cp new.txt old.txtwould overwriteold.txt. - Copying onto a file that exists:
cpreplaces it without asking.
Tap Run to copy your notes, then type ls to see both files.
Try it:
cp notes.txt notes-copy.txtlearner@shellstreak: ~
Starting your practice shell…
You can also type in the terminal yourself. Try anything: you can't break it.
Go deeper: Basic terminal commands for beginners