Skip to content
zero2vibecodelearn vibe coding
Level 2 · Working with content 5 min Reviewed by the author · Aug 4, 2026

Copying and moving: cp and mv

`cp` duplicates a file, `mv` moves it — and because moving something to a new name in the same folder is a rename, `mv` is also how you rename.

Level 2 · 0 / 4 lessons0%

Two commands, one shape:

cp source destination
mv source destination

The difference is only what happens to the source. cp leaves it alone. mv does not.

cp — copy

cp report.txt report-backup.txt

Now there are two files with identical content. Silent, as usual.

You can copy into a folder instead of to a new name:

cp report.txt ~/backup/

When the destination is a folder, the copy keeps its original name and lands inside. So that command creates ~/backup/report.txt.

Note

Copying a folder needs the -r flag, for recursive — meaning “and everything inside it, all the way down”. cp -r projects backup-projects. Without -r, cp refuses and tells you why.

Quick check

You run `cp notes.txt archive/`. Where does the copy end up?

mv — move, and also rename

mv report.txt ~/backup/

Same idea, except the original is gone from where it was.

And here is the piece that surprises people: because moving a file to a new name in the same folder is indistinguishable from renaming it, mv is the rename command:

mv report.txt report-final.txt

There is no separate rename in the classic toolkit. There does not need to be.

Quick check

What does `mv draft.md final.md` do when both names are in the current folder?

The thing both of them will do to you

Neither cp nor mv asks before overwriting the destination. If backup.txt already exists and you run cp notes.txt backup.txt, the old backup.txt is simply gone.

Important

ls the destination before you copy or move onto it. That is the whole safety procedure, and it takes two seconds. There is no undo and no confirmation .

Try it

You are in work, with report.txt and draft.md. There is an empty backup folder next door.

  1. ls — see what you have.
  2. cp report.txt ~/backup/ — keep a copy safe.
  3. mv report.txt report-final.txt — rename the original.
  4. ls — the folder now shows report-final.txt, not report.txt.
  5. ls ~/backup — the copy is still there under its original name.

Step 5 is the point of the exercise: the copy you made before renaming is untouched by the rename. Copies are independent from the moment they exist.

Check your understanding

Answered 0/3
Mode:

What is the difference between `cp` and `mv`?

How do you rename a file?

You run `cp notes.txt backup.txt`, and backup.txt already exists. What happens?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Copy report.txt into the backup folder, then rename the original to report-final.txt.

Tab complete · history · Ctrl+L clear · help commands

  • Not done: Copy a file with cp
  • Not done: The copy landed in backup
  • Not done: Rename a file with mv
  • Not done: The original is now report-final.txt

Lesson Q&A

What is the difference between `cp` and `mv`?

After cp you have two copies. After mv you have one, in a new place or under a new name.

How do you rename a file?

There is no separate rename command in the classic Unix toolkit. mv covers both jobs because they are the same operation.

You run `cp notes.txt backup.txt`, and backup.txt already exists. What happens?

cp and mv overwrite the destination without asking. Check the destination before you run them.

You run `cp notes.txt archive/`. Where does the copy end up?

A destination that is an existing folder means 'put it in here, same name'.

What does `mv draft.md final.md` do when both names are in the current folder?

Same folder, new name — that is a rename. mv is the only command you need for it.

Move between lessons with · search with ⌘K