Skip to main content

mv Cheatsheet

By Dejan Panovski Updated on Download PDF

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.

CommandDescription
mv [OPTIONS] SOURCE DESTMove or rename one file/directory
mv [OPTIONS] SOURCE... DIRECTORYMove multiple sources into destination directory
mv file.txt newname.txtRename file in same directory
mv dir1 dir2Rename directory

Move Files

Move files between directories.

CommandDescription
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.txtMove and rename in one step

Move Directories

Move or rename complete directory trees.

CommandDescription
mv project/ /opt/Move directory to another location
mv olddir newdirRename directory
mv dir1 dir2 /dest/Move multiple directories
mv /src/dir /dest/dir-newMove and rename directory

Overwrite Behavior

Control what happens when destination already exists.

CommandDescription
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.

CommandDescription
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.

CommandDescription
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.

IssueCheck
No such file or directoryVerify source path with ls -l source
Permission deniedCheck destination permissions and ownership
Wrong file overwrittenUse -i or -n for safer moves
Wildcard misses hidden files* does not match dotfiles by default
Option-like filename failsUse -- before source names

Use these guides for detailed move and rename workflows.

GuideDescription
How to Move Files in Linux with mv CommandFull mv guide with examples
How to Rename Files in LinuxFile renaming patterns and tools
How to Rename Directories in LinuxDirectory rename methods
Cp Command in Linux: Copy Files and DirectoriesCompare copy vs move workflows