Navigation and files

Command mv

Move or rename a file

Linux · Bash examples · commands run on the selected server

When to use mv

Use mv to rename a path or move it to another directory. Check for existing destinations before moving configuration or project files; a move across filesystems is not the same operation as a simple rename.

Syntax

mv [PARAMETERS] SOURCE DESTINATION

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-i
Ask before overwriting.
-n
Do not replace an existing file.
-v
Show each completed move.

Usage examples

Rename file

mv -i ./draft.txt ./report.txt

The file is renamed, with a confirmation if the destination already exists.

Move file to directory

mv -i ./report.txt ./archive/

The file moves into an existing archive directory and keeps its basename.

Rename directory

mv -i ./project-old ./project

The directory is renamed unless the destination is already a directory, which changes the resulting layout.

Notes and limitations

  • On one file system, moving usually amounts to renaming; between file systems, data is copied and deleted.
  • Check the destination path: an existing file may be overwritten.

Common questions and troubleshooting

Does mv always finish atomically?

Renaming a file within one filesystem can be atomic. Moving it to a different filesystem requires copying it and then deleting the original, so it is not an atomic operation.

How can I avoid replacing a file accidentally?

Interactive mode asks before replacement in an interactive session. For automation choose explicit collision handling and inspect the destination before committing a move.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man mv.