AI Hints
Home›Linux Tutorial›Copy, Move, Remove
Linux · Lesson 26 of 120

mv: Moving and Renaming

One command, two jobs.

⏱ 2 min read▶ Video at 31:33🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Moving a file, and renaming a file, sound like two different jobs. But to Linux, they're the same thing. Both just change where a file lives, and what it's called. So one command does both. MV, short for move.

mv: Moving and Renaming
From the video: mv: Moving and Renaming
  • Moving and renaming
  • The same job to Linux
  • mv does both

Renaming

To rename, move the file to a new name in the same folder. MV to do dot TXT, tasks dot TXT. The old name is gone, and the file now has its new name. Unlike copy, there's still only one file.

Terminal
mv todo.txt tasks.txt
ls
Documents  Downloads  Music  Pictures  notes.txt  tasks.txt

Moving into a folder

To move, give a folder as the destination. Here we move notes dot TXT into Documents. It disappears from home, and appears in Documents. Moving folders works the same way, and doesn't need dash R.

Terminal
mv notes.txt Documents
ls
Documents  Downloads  Music  Pictures  todo.txt
ls Documents
cv.txt  notes.txt  report.txt

Careful: no undo

There's one danger with MV and CP. If the destination file already exists, it's replaced, without any warning. There's no recycle bin. Dash I, for interactive, makes them ask first. Dash N means never overwrite. When in doubt, check with LS before you move.

keyvalue
Dangerreplaces existing files
No warningby default
-iask before replacing
-nnever overwrite

Summary

MV renames when the destination is a new name, and moves when it's a folder. And watch out, it overwrites without asking, unless you use dash I. Next, deleting.

Key takeaways
  • mv old new: rename
  • mv file folder: move
  • -i asks first
Next up: rm: Removing Files — deleting, carefully