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

OptionWhat it does
-iInteractive: ask before overwriting an existing file.
-nNever overwrite an existing file.
-vVerbose: show each move as it happens.
-bMake 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

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

ls

List the contents of a directory, with options for hidden files, long format, sorting and more.

mkdir

Create one or many directories, including whole nested paths with -p.

rm

Delete files and directories — and understand -r, -f and why there is no trash bin.

cp

Copy files and whole directory trees, preserving attributes when needed.

Want to build real fluency? The interactive course takes you through mv and every other essential command with guided, checked exercises.