mv

Updated

September 4, 2026

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

  1. Rename files and directories
  2. Move into another directory
  3. Atomic replace of configs (mv new current)
  4. Bulk relocate with shell globs
  5. 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/ *.log

Interactive / no-clobber

mv -i *.md docs/
mv -n src dest              # leave dest if it exists

Atomic 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.conf

Readers 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 options

Directory edge cases

mv dir existing_dir/        # moves dir *into* existing_dir
mv -T dir existing_file     # refuse treating dest as directory

Cross-device awareness

df -P file.txt /mnt/usb
mv file.txt /mnt/usb/       # copy+delete if different devices

Swap two files (bash)

mv a.tmp a.bak && mv a a.tmp && mv a.bak a
# or use a third temporary name carefully

Notes / Pitfalls

  • Running processes that already hold an open file descriptor keep the old inode after you mv a 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.
  • mv does 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 foo remains the standard atomic publish on POSIX local filesystems.
  • For directory trees across mounts, prefer rsync then delete, or tar pipelines, 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