The mv command moves or renames a file in one step
To move a file in terminal, type mv followed by the file name, a space, and the destination folder. For example, mv document.txt ~/Desktop moves document.txt from your current location to your Desktop. The file disappears from where it was and appears in the new location — it does not stay in both places.
The mv command also renames files. Type mv oldname.txt newname.txt to rename a file in place. You can do both at once: mv oldname.txt ~/Desktop/newname.txt moves the file to Desktop and renames it in a single command.
Unlike copying, mv does not leave a duplicate behind. The original file ceases to exist in its old location. This matters when you are working with large files or trying to free up space — moving is faster and uses no extra disk room.
Key Takeaways
- The mv command moves a file to a new folder and removes it from the old one in a single action.
- You can rename a file at the same time you move it by including the new name in the destination path.
- Use the full path to the destination folder if you are not sure where you are in the terminal, or use ~ to mean your home directory.
- If a file with that name already exists in the destination, mv will overwrite it without asking — use mv -i to get a warning first.
The basic syntax: what each part means
The mv command follows a straightforward pattern: mv [source] [destination]. The source is the file you want to move. The destination is where you want it to go — either a folder path or a new file name.
If you are moving a file called report.pdf from your current folder to a folder called Archive, you type mv report.pdf Archive. Terminal assumes Archive is a folder inside your current location. If Archive is somewhere else, you need to give the full path: mv report.pdf ~/Documents/Archive or mv report.pdf /Users/yourname/Documents/Archive.
The tilde symbol ~ is a shortcut that means your home directory — the folder that opens when you click your user name in Finder. Using ~ saves you from typing the full path every time.
Moving files to specific folders you know the path to
If you know exactly where you want the file to go, type the full path. Open Finder, navigate to the destination folder, and look at the folder name in the window title or the address bar. Then use that path in your mv command.
For example, to move a file called invoice.xlsx to a folder called Finances inside your Documents folder, type mv invoice.xlsx ~/Documents/Finances. Terminal moves the file and keeps the original file name. If you want to rename it at the same time, type mv invoice.xlsx ~/Documents/Finances/invoice_2024.xlsx.
If the destination folder does not exist, mv will fail and show an error. Create the folder first using mkdir foldername, then run the mv command again.
Renaming a file while you move it
You do not have to move and rename in two separate steps. Include the new name as part of the destination path, and mv does both at once.
Type mv oldreport.txt ~/Desktop/newreport.txt to move oldreport.txt to Desktop and rename it to newreport.txt in one command. This is faster than moving first and renaming second, and it leaves no confusion about which version is which.
You can also rename a file without moving it by using the same folder as both source and destination: mv oldname.txt newname.txt. This works only if you are already in the folder where the file lives.
Protecting yourself from accidental overwrites
If a file with the same name already exists in the destination folder, mv will replace it without asking. You lose the old file permanently. To prevent this, use the -i flag, which stands for interactive: mv -i document.txt ~/Desktop.
With the -i flag, terminal asks you to confirm before overwriting. You type y to proceed or n to cancel. This takes an extra second but protects you from accidentally destroying a file you meant to keep.
Another option is the -n flag, which means "do not overwrite." Type mv -n document.txt ~/Desktop, and if a file called document.txt already exists on Desktop, mv will skip the move entirely and show no error. Use -n when you want to move only files that do not already exist in the destination.
Moving multiple files at once
You can move several files to the same folder in one command. Type mv file1.txt file2.txt file3.txt ~/Archive to move all three files to the Archive folder. The last item in the command must be a folder — terminal assumes anything after the first file name is a destination.
To move all files of a certain type, use a wildcard. Type mv *.pdf ~/Documents/PDFs to move every PDF file in your current folder to the PDFs folder. The asterisk means "any file name" — *.pdf matches report.pdf, invoice.pdf, and anything else ending in .pdf.
Be careful with wildcards. If you type mv *.txt newname.txt, terminal will try to rename multiple files to the same name, which fails. Wildcards work for moving to a folder, but not for renaming multiple files at once.
Troubleshooting common mv errors
If you see "No such file or directory," the source file does not exist or the destination folder does not exist. Check the file name for typos and make sure the destination folder is spelled correctly. Use ls to list files in your current folder and verify the name.
If you see "Is a directory," you tried to move a folder but forgot the -r flag. Moving folders requires mv -r foldername destination. However, mv works on folders by default in most cases — the error usually means something else went wrong with the path.
If the file moved but you cannot find it, use the find command to search: find ~ -name "filename.txt". This searches your entire home directory for the file. It takes a few seconds but tells you exactly where the file ended up.
Frequently Asked Questions
Can I move a file to a folder that does not exist yet?
No. The destination folder must exist before you run mv. Create it first with mkdir foldername, then move the file. If you try to move to a folder that does not exist, terminal shows an error and the file stays where it is.
What is the difference between mv and cp?
The cp command copies a file, leaving the original in place and creating a duplicate in the destination. The mv command moves the file, removing it from the original location. Use cp when you want two copies; use mv when you want to relocate the file.
Can I undo a move if I made a mistake?
Terminal does not have an undo button. If you moved a file to the wrong place, you have to move it again to the correct location. This is why the -i flag is useful — it asks you to confirm before overwriting, giving you a chance to catch mistakes.
How do I move a file if the file name has spaces in it?
Put the file name in quotes: mv "my document.txt" ~/Desktop. Without quotes, terminal treats each word as a separate item and the command fails. Quotes tell terminal to treat the whole thing as one file name.
Can I move a folder and everything inside it?
Yes. The mv command works on folders the same way it works on files. Type mv foldername ~/Desktop to move the entire folder and all its contents to Desktop. You do not need any special flags — mv handles folders automatically.