1/8

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.txt

What happened

  • No output. notes-copy.txt now exists, with exactly the same lines as notes.txt; cat notes-copy.txt shows them.

Common mistakes

  • Swapping the order. The source comes first: cp new.txt old.txt would overwrite old.txt.
  • Copying onto a file that exists: cp replaces it without asking.

Tap Run to copy your notes, then type ls to see both files.

Try it:cp notes.txt notes-copy.txt
learner@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