mv moves a file, and renaming is the same operation seen from a different angle. Learn how moving within one directory becomes a rename, and how to avoid the silent overwrite, by running the commands in a real terminal in your browser.
Updated: 2026-09-05
mv [options] source destination
The source is gone and it appears at the destination. If the destination is a directory the file lands inside it, otherwise that becomes its new name.
The terminal on this page holds a few files and an archive/ directory.
$ ls
archive draft.txt notes.txt old.log src
Start with a rename.
$ mv draft.txt article.txt
Like cp, mv prints nothing when it works.
ls shows that draft.txt is gone and article.txt is here.
$ ls
archive article.txt notes.txt old.log src
That is all a rename is: moving a file to a different name in the same directory.
Name a directory as the destination and the file goes inside it.
$ mv old.log archive/
$ ls archive
old.log
It is no longer where it was.
$ ls
archive article.txt notes.txt src
You can move and rename in one step by writing both the directory and the new name.
$ mv notes.txt archive/notes.txt
$ ls
archive article.txt src
mv is mostly how you fix where things live.
| Situation | What you type |
|---|---|
| Promote a draft to its real name | mv draft.md release-notes.md |
| Sweep old logs out of the way | mv *.log archive/ |
| Move a config one level up | mv config.json .. |
| Move without overwriting anything | mv -n notes.txt archive/ |
An existing file is overwritten silently.
Just like cp, mv does not ask.
-i prompts before replacing, and -n refuses to touch files that already exist.
A missing source is an error.
$ mv nope.txt archive/
mv: cannot stat 'nope.txt': No such file or directory
Either the name is misspelled, or you are not where you think you are.
How you write the destination changes the result.
mv a.txt backup moves into backup when that directory exists, and renames the file to backup when it does not.
Writing backup/ with the trailing slash keeps the intent explicit.
webterm.app
Terminal Fundamentals
Learn commonly used commands
learn.webterm.app

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the coursemv is also in the “Move and copy” section of the Linux Commands Cheat Sheet.