mv
Overview
mv renames or moves files and directories. On the same filesystem, rename is typically atomic and instant (directory entry update). Across filesystems, mv copies then deletes, which is slower, non-atomic, and can change performance and link behavior.
Syntax
mv [options] source dest
mv [options] source... directory
mv [options] -t directory source...Common Options
| Option | Description |
|---|---|
-i, --interactive |
Prompt before overwrite |
-n, --no-clobber |
Do not overwrite |
-f, --force |
Do not prompt (default in many cases) |
-u, --update |
Move only when source is newer or dest missing |
-v, --verbose |
Print each move |
-b, --backup |
Backup existing destinations |
-S SUF |
Backup suffix |
-t DIR |
Target directory first |
-T |
Treat dest as a normal file (not a directory) |
--strip-trailing-slashes |
Remove trailing slashes from sources |
Key Use Cases
- Rename files and directories
- Move into another directory
- Atomic replace of configs (
mv new current) - Bulk relocate with shell globs
- Safer overwrite policies (
-i/-n)
Examples with Explanations
Rename and move
mv old.txt new.txt
mv file.txt /tmp/
mv chapter.md docs/
mv -t /backup/ *.logInteractive / no-clobber
mv -i *.md docs/
mv -n src dest # leave dest if it existsAtomic replace pattern
cp app.conf app.conf.bak
install -m 644 app.conf.new /etc/myapp/app.conf.new
mv /etc/myapp/app.conf.new /etc/myapp/app.confReaders opening the path see old or new content, not a partial write (when same filesystem).
Verbose bulk
mv -v *.png ~/Pictures/Backup on conflict
mv -b file.txt /dest/file.txt
# creates file.txt~ or numbered backups depending on optionsDirectory edge cases
mv dir existing_dir/ # moves dir *into* existing_dir
mv -T dir existing_file # refuse treating dest as directoryCross-device awareness
df -P file.txt /mnt/usb
mv file.txt /mnt/usb/ # copy+delete if different devicesSwap two files (bash)
mv a.tmp a.bak && mv a a.tmp && mv a.bak a
# or use a third temporary name carefullyNotes / Pitfalls
- Running processes that already hold an open file descriptor keep the old inode after you
mva replacement into place — they won’t see new content until reopen. - Cross-device moves break hard links and expand sparse files unless tools special-case them.
- Globs that accidentally match the destination directory can error or nest oddly — quote and order carefully.
mvdoes not update application-internal paths stored inside files.- Permissions: need write access on source’s parent and dest’s parent.
2026-relevant notes
- Deploy pattern: write
foo.new→ fsync →mv foo.new fooremains the standard atomic publish on POSIX local filesystems. - For directory trees across mounts, prefer
rsyncthen delete, ortarpipelines, for progress and resumability. - On overlay/container layers, “rename atomicity” still holds within a layer but publishing images is a different model.
Additional Resources
man mv