# Copying and moving: cp and mv

Course: Terminal Basics — https://zero2vibecode.com/learn/terminal-basics
Canonical URL: https://zero2vibecode.com/learn/terminal-basics/2-3-copy-and-move

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

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

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.

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

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

`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 prompt.

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