Skip to content
English
Level 1: Your First 30 Minutes in the Terminal
Lesson 8 · +10 XP

Moving and renaming

In a file explorer, renaming and moving feel like different things. You right-click → Rename to change a name. You drag and drop to move.

In the terminal, they’re the same command: mvmove. A rename is just a move where the destination is “right here, but with a different name.”

Once that clicks, the command stops feeling weird and starts feeling elegant.

Renaming a file

The shape is the same as cp: mv source destination.

echo "todo list" > todo.txt
mv todo.txt tasks.txt

Run ls. The file is now called tasks.txt. The old name is gone — not deleted, just moved to a new name in the same folder.

Moving a file into a folder

If the destination is an existing folder, the file slides in there, keeping its name:

mkdir archive
mv tasks.txt archive

Now ls doesn’t show tasks.txt anymore in your current folder. ls archive does. The file moved.

Moving and renaming at once

You can give the new name as part of the destination:

mv archive/tasks.txt archive/old-tasks.txt

Or move and rename in one step:

mv draft.txt archive/draft-v1.txt

One command, two operations. Very satisfying.

Folders work the same — no -r needed

Unlike cp, mv works on folders without any special flag:

mv archive backups

If backups doesn’t exist, this renames archive to backups. If backups does exist and is a folder, this moves archive inside backups.

That little ambiguity is one of the few moments the terminal trips beginners. The rule:

  • Destination doesn’t exist → rename source to that name.
  • Destination is an existing folder → put source inside it.

Run pwd and ls afterward if you’re not sure what happened. The terminal will tell you the truth — you just have to ask.

The footgun (you’re sensing a pattern by now)

Like cp, mv overwrites silently if the destination already has a file with that name.

If archive/tasks.txt already exists and you run mv tasks.txt archive/, the existing one is replaced. No warning. No undo.

The same -i flag works:

mv -i tasks.txt archive/

It’ll prompt before overwriting. Slower, safer.

Why mv is dangerous in a quiet way

cp makes a duplicate — even if you mess up the destination, the original is still there. mv is one-shot: if you typo the destination, your file might land somewhere unexpected, or it might overwrite something. Run ls after every mv in unfamiliar places. The 0.3 seconds of paranoia has paid off for everyone who’s ever typed at a terminal.

What you’ve learned

  • mv source dest — rename (when dest doesn’t exist) or move (when dest is an existing folder).
  • mv works on folders without any flag — no -r needed.
  • mv -i — ask before overwriting.

You can create, copy, and move. The last verb in your starter toolkit is the scariest one: delete. Next lesson, we treat it with the respect it deserves.