What is mv

mv moves or renames files and directories. Unlike cp, it does not create a copy — the original path stops existing. When source and destination are on the same filesystem, mv just updates the directory entry (instant, no data copied). Across filesystems it copies the data and then removes the source.

Rename a file

mv oldname.txt newname.txt

Move a file to a directory

mv file.txt /home/user/documents/

Move multiple files to a directory

mv file1.txt file2.txt image.png /home/user/documents/

Move a directory

mv old-project/ new-project/

If new-project/ already exists, old-project/ is moved inside it. If it does not exist, old-project/ is renamed to new-project/.

Useful options

Ask before overwriting -i

mv -i source.txt dest.txt

Prompts for confirmation if dest.txt already exists. Good habit when moving files manually.

Never overwrite -n

mv -n source.txt dest.txt

Silently does nothing if the destination exists.

Create a backup -b

mv -b source.txt dest.txt

If dest.txt exists, it is renamed to dest.txt~ before being overwritten.

Verbose output -v

mv -v *.log /var/log/archive/

Prints each move as it happens — useful when moving many files.

Move only if source is newer -u

mv -u source.txt dest.txt

Skips the move if dest.txt exists and is the same age or newer.

Batch rename with a loop

mv has no built-in glob-rename. Use a shell loop:

for f in *.txt; do mv "$f" "${f%.txt}.md"; done

This renames every .txt file to .md in the current directory.

Or use the rename utility (Debian/Ubuntu):

rename 's/\.txt$/.md/' *.txt

Move files matching a pattern

mv *.log /var/log/archive/
mv report-2024-*.pdf /archive/2024/

Practical examples

Rename a directory after a project is finished:

mv project-wip/ project-done/

Move config files to a backup location before editing:

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

Reorganize downloads by type:

mv ~/Downloads/*.pdf ~/Documents/pdfs/
mv ~/Downloads/*.jpg ~/Pictures/

See also

man mv, rename(1) for regex-based bulk renaming, rsync for copying with more control over overwrites.

  • Created: August 30, 2007
  • Last edited: July 7, 2026