The mv command moves or renames files and folders.
mv oldname.txt newname.txt # Rename a file
mv file.txt ~/Documents/ # Move to Documents
Rename a File
mv report.txt report-final.txt
The file stays in the same folder with a new name.
Move a File to Another Folder
mv file.txt ~/Downloads/
The file moves to Downloads, keeping its name.
Move and Rename at Once
mv file.txt ~/Downloads/newname.txt
Moves the file and renames it in one command.
Move Multiple Files
mv file1.txt file2.txt file3.txt ~/Documents/
All three files move to Documents.
Or use wildcards:
mv *.jpg ~/Pictures/
Moves all .jpg files to Pictures.
Move a Folder
mv myfolder/ ~/Documents/
Moves the entire folder and its contents.
Common Examples
| Command | What it does |
|---|---|
mv a.txt b.txt |
Rename a.txt to b.txt |
mv a.txt ~/Desktop/ |
Move a.txt to Desktop |
mv *.png images/ |
Move all PNGs to images folder |
mv old-folder/ new-folder/ |
Rename a folder |
mv file.txt ../ |
Move up one directory |
mv file.txt . |
Move to current directory |
Prevent Accidental Overwrites
If the destination file already exists, mv silently overwrites it. To get a warning:
mv -i file.txt ~/Documents/
The -i flag prompts before overwriting.
Make it your default:
alias mv="mv -i"
Add that to your .zshrc.
Force Move (No Prompts)
If you want to overwrite without asking:
mv -f file.txt ~/Documents/
Use with caution.
Verbose Mode
See what's happening:
mv -v file.txt ~/Documents/
Output: file.txt -> /Users/you/Documents/file.txt
Move Hidden Files
Hidden files (starting with .) aren't matched by *. To move them:
mv .* ~/destination/
Or be more specific:
mv .gitignore .env ~/project/
Move All Files from a Folder
mv source-folder/* destination-folder/
This moves the contents, not the folder itself.
To include hidden files:
mv source-folder/* source-folder/.* destination-folder/
Rename with a Pattern
To rename multiple files with a pattern, combine mv with a loop:
for f in *.jpeg; do mv "\$f" "\${f%.jpeg}.jpg"; done
This renames all .jpeg files to .jpg.
Undo a Move
Just move it back:
mv ~/Documents/file.txt ~/Desktop/
There's no built-in undo, but moves are reversible if you remember where the file was.
Common Mistakes
Forgetting the trailing slash:
mv file.txt folder # If 'folder' doesn't exist, this renames file.txt to 'folder'
mv file.txt folder/ # This correctly moves into the folder
Overwriting files accidentally:
mv newfile.txt existingfile.txt # existingfile.txt is gone
Use mv -i to prevent this.
Wrong directory:
Always check your location with pwd before moving files.
mv vs cp
| Command | What it does |
|---|---|
mv |
Moves the file (original is gone) |
cp |
Copies the file (original stays) |
Use cp when you want to keep the original.
Move to Trash Instead of Delete
mv is also useful for "safe deletes":
mv file.txt ~/.Trash/
The file goes to Trash instead of being permanently deleted.
Batch Move by File Type
mv *.pdf ~/Documents/PDFs/
mv *.mp3 ~/Music/
mv *.jpg *.png ~/Pictures/
Organize files by type in one line.
Keep Learning
mv is one of the essential file commands. The free course covers this and other fundamentals.
Check it out at Mac Terminal for Humans.