The mv command in Linux
mv moves files and directories. Renaming is simply moving to a new name in the same place, which is why Linux has no separate "rename" command for everyday use. Unlike cp, mv does not need -r for directories, and moving within the same filesystem is instantaneous regardless of size — only the directory entry changes.
How mv works
Within one filesystem, mv is the rename() system call: the directory entry is rewritten to point the name at a new location, and not one byte of file data moves. That is why moving a 100 GB file to another folder on the same disk is instantaneous — and why rename() is atomic: at every instant, the name refers to exactly one complete file, old or new.
Across filesystems the trick is impossible — inode numbers only mean something within their own filesystem — so rename() fails with EXDEV and mv silently falls back to copy-then-delete. Suddenly the "move" takes real time, needs free space on the destination, and loses its atomicity. Every deployment pattern built on atomic renames (write temp file, mv over the real one) carries the same fine print: same filesystem only.
Syntax
mv [OPTIONS] SOURCE... DEST Common options
| Option | What it does |
|---|---|
-i | Interactive: ask before overwriting an existing file. |
-n | Never overwrite an existing file. |
-v | Verbose: show each move as it happens. |
-b | Make a backup of any file that would be overwritten. |
How to use mv: examples
$ mv draft.txt final.txt Rename a file.
$ mv report.pdf documents/ Move a file into a directory, keeping its name.
$ mv documents/report.pdf archive/2026-report.pdf Move and rename in a single operation.
$ mv old-name-dir new-name-dir Rename a directory — no -r needed, unlike cp.
$ mv *.png images/ Move every PNG in the current directory into images/.
Real-world use cases for mv
Atomic file replacement
Writing a file that other processes read (a config, a data feed) risks readers seeing a half-written file. The standard pattern: write to data.json.tmp, then mv data.json.tmp data.json. Within one filesystem, mv is atomic — readers see the old file or the new one, never a partial.
Reorganizing a download mess
mv ~/Downloads/*.pdf ~/Documents/papers/ sweeps every PDF into its home in one command. Combined with a couple more globs for images and archives, a chaotic Downloads folder is sorted in under a minute.
Try mv yourself
This is a live sandbox with a small filesystem (documents/, notes.txt,
backup.sh…). Nothing you do here can break anything — experiment freely.
Try: mv notes.txt ideas.txt
Pro tips and common mistakes
- mv within the same filesystem is instant regardless of file size — only the directory entry changes. Across filesystems it becomes a copy+delete and takes real time.
- The atomic-rename trick (write temp, mv over) only works within one filesystem — moving across mount points loses atomicity.
- Batch renaming is not mv's job: for report-1.txt → 2026-report-1.txt patterns, use the rename utility or a small for loop.
- mv -i is worth aliasing (alias mv="mv -i") on machines where you're tired: it asks before silently overwriting.
Frequently asked questions about mv
How do I rename a file in Linux?
Use mv oldname newname. Renaming and moving are the same operation: you are giving the file a new path.
Does mv need -r for directories?
No. mv moves directories without any special flag, because it relocates the directory entry rather than copying contents.
Does mv overwrite existing files?
Yes, silently by default. Use mv -i to be prompted or mv -n to refuse overwriting.
Related commands
List the contents of a directory, with options for hidden files, long format, sorting and more.
mkdirCreate one or many directories, including whole nested paths with -p.
rmDelete files and directories — and understand -r, -f and why there is no trash bin.
cpCopy files and whole directory trees, preserving attributes when needed.