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 DESTINATIONSquare 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
Usage examples
Rename file
mv -i ./draft.txt ./report.txtThe 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 ./projectThe 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.