mv Cheatsheet
Quick reference for moving and renaming files and directories with mv in Linux
The mv command moves or renames files and directories in Linux. This cheatsheet covers common mv patterns for renaming, moving, overwrite control, backups, and safe bulk operations.
Basic Syntax
Core command forms for move and rename operations.
| Command | Description |
|---|---|
mv [OPTIONS] SOURCE DEST | Move or rename one file/directory |
mv [OPTIONS] SOURCE... DIRECTORY | Move multiple sources into destination directory |
mv file.txt newname.txt | Rename file in same directory |
mv dir1 dir2 | Rename directory |
Move Files
Move files between directories.
| Command | Description |
|---|---|
mv file.txt /tmp/ | Move one file to another directory |
mv file1 file2 /backup/ | Move multiple files |
mv *.log /var/log/archive/ | Move files matching pattern |
mv /src/file.txt /dest/newname.txt | Move and rename in one step |
Move Directories
Move or rename complete directory trees.
| Command | Description |
|---|---|
mv project/ /opt/ | Move directory to another location |
mv olddir newdir | Rename directory |
mv dir1 dir2 /dest/ | Move multiple directories |
mv /src/dir /dest/dir-new | Move and rename directory |
Overwrite Behavior
Control what happens when destination already exists.
| Command | Description |
|---|---|
mv -i file.txt /dest/ | Prompt before overwrite |
mv -n file.txt /dest/ | Never overwrite existing file |
mv -f file.txt /dest/ | Force overwrite without prompt |
mv -u file.txt /dest/ | Move only if source is newer |
Backup and Safety
Protect destination files while moving.
| Command | Description |
|---|---|
mv -b file.txt /dest/ | Create backup of overwritten destination |
mv --backup=numbered file.txt /dest/ | Numbered backups (.~1~, .~2~) |
mv -v file.txt /dest/ | Verbose output |
mv -iv file.txt /dest/ | Interactive + verbose |
Useful Patterns
Common real-world mv command combinations.
| Command | Description |
|---|---|
mv -- *.txt archive/ | Move files when names may start with - |
mv "My File.txt" /dest/ | Move file with spaces in name |
find . -maxdepth 1 -name '*.tmp' -exec mv -t /tmp/archive {} + | Move matched files safely with find |
mv /path/file{,.bak} | Quick rename via brace expansion |
Troubleshooting
Quick checks for common move/rename errors.
| Issue | Check |
|---|---|
No such file or directory | Verify source path with ls -l source |
Permission denied | Check destination permissions and ownership |
| Wrong file overwritten | Use -i or -n for safer moves |
| Wildcard misses hidden files | * does not match dotfiles by default |
| Option-like filename fails | Use -- before source names |
Related Guides
Use these guides for detailed move and rename workflows.
| Guide | Description |
|---|---|
How to Move Files in Linux with mv Command | Full mv guide with examples |
How to Rename Files in Linux | File renaming patterns and tools |
How to Rename Directories in Linux | Directory rename methods |
Cp Command in Linux: Copy Files and Directories | Compare copy vs move workflows |