Moving & Renaming with mv
mv moves files between directories and is also how you rename them.
Syntax
mv [options] source destinationmv moves a file from one place to another. If the destination is in the same directory but a different name, the effect is a rename — there is no separate rename command in Linux.
Two uses in one command
- Move:
mv file.txt archive/— into another folder. - Rename:
mv old.txt new.txt— same folder, new name.
Unlike cp, moving a directory does not need -r. Add -i to be warned before overwriting.
Example
# Rename a file
mv draft.txt final.txt
# Move a file into a folder
mv final.txt documents/
# Move and rename in one step
mv documents/final.txt documents/report-2026.txtWhen to use it
- A developer renames 'app.js' to 'index.js' with 'mv app.js index.js' without creating a copy.
- A sysadmin moves a completed log file from '/tmp/process.log' to '/var/log/archive/' to organise logs.
- A script uses 'mv -i' when moving user files to prompt before overwriting any existing destination file.
More examples
Rename and move files
Shows 'mv' both as a rename operation and as a file relocation to a different directory.
# Rename a file in place
mv oldname.txt newname.txt
# Move file to another directory
mv report.pdf /home/alice/documents/Move directory and prompt on overwrite
Moves a whole directory tree and uses -i (interactive) to prevent accidentally overwriting destination files.
# Move an entire directory
mv ./old-project/ ./archive/2025/
# -i prompts before overwriting existing files
mv -i data.csv /shared/exports/Rename files with brace expansion
Uses brace expansion and command substitution to rename files concisely in one-liners.
# Rename by changing extension
mv server.{js,mjs}
# Equivalent to: mv server.js server.mjs
# Add a date suffix to a file
mv access.log access.log.$(date +%Y%m%d)
Discussion