The mv command moves or renames files and folders in Linux
The mv command is how you move files from one location to another in Linux. It also renames files in place. Unlike copying, mv removes the file from its original location — it does not leave a duplicate behind. The basic syntax is mv source destination, where source is the file or folder you want to move and destination is where it should go.
You can move a single file, multiple files at once, or entire folders with their contents. The command works the same way whether you are moving something across your home directory or to a completely different part of the filesystem. Understanding when to use mv instead of cp (copy) and how to avoid common mistakes will save you time and prevent accidental data loss.
Key Takeaways
- The mv command moves files and folders to a new location and removes them from the original spot, unlike cp which leaves a copy behind.
- To move a single file, type mv filename /path/to/destination/ — the trailing slash tells Linux the destination is a folder.
- Moving multiple files at once requires listing each one: mv file1 file2 file3 /destination/ — the last argument must be a folder.
- Use mv -i to ask for confirmation before overwriting a file that already exists at the destination.
- Renaming a file is the same operation as moving it: mv oldname newname moves the file to a new name in the same folder.
Moving a single file to a new location
To move one file, type mv filename /path/to/destination/. For example, if you have a file called report.txt in your current folder and you want to move it to your Documents folder, you would type mv report.txt ~/Documents/. The tilde (~) is a shortcut for your home directory.
The trailing slash after the destination folder is optional but recommended — it makes clear to Linux that the destination is a folder, not a file. Without it, if a file named Documents already exists, Linux might try to rename report.txt to Documents instead of moving it inside a Documents folder. With the slash, there is no ambiguity.
If you do not include a path at all, just a filename, Linux assumes you mean the current folder. So mv report.txt newname.txt renames the file in place without moving it anywhere.
Moving multiple files at once
To move several files to the same destination, list each filename separated by a space, then the destination folder at the end: mv file1 file2 file3 ~/Documents/. The last argument must be a folder — Linux will not let you move multiple files into a single file.
You can also use wildcards to move groups of files. For example, mv *.txt ~/Documents/ moves every file ending in .txt from your current folder to Documents. The asterisk (*) matches any characters, so *.pdf would match report.pdf, notes.pdf, and anything else ending in .pdf.
If you want to move all files of a certain type from a subfolder, you can combine the path with a wildcard: mv ~/Downloads/*.jpg ~/Pictures/ moves every jpg file from Downloads to Pictures.
Moving folders and their contents
The mv command works on folders the same way it works on files. To move an entire folder and everything inside it, type mv foldername /path/to/destination/. For example, mv ~/Downloads/old_project ~/Documents/ moves the old_project folder and all its files and subfolders into Documents.
You do not need any special flag or option to move a folder — mv handles it automatically. The folder keeps its name and structure; only its location changes. If you want to move the folder and rename it at the same time, you can do that too: mv ~/Downloads/old_project ~/Documents/new_name moves the folder and renames it to new_name in one step.
Renaming files with mv
Renaming a file is technically the same operation as moving it — you are just moving it to a new name in the same location. Type mv oldname newname. For example, mv report.txt final_report.txt renames report.txt to final_report.txt in your current folder.
You can rename and move at the same time by including a path: mv ~/Downloads/report.txt ~/Documents/final_report.txt moves the file from Downloads to Documents and renames it in one command. This is faster than moving first and renaming second.
Avoiding accidental overwrites
If a file with the same name already exists at the destination, mv will overwrite it without asking — the original file is deleted and replaced. To prevent this, use the -i flag (interactive mode): mv -i report.txt ~/Documents/. Now if a file named report.txt already exists in Documents, Linux will ask you whether you want to overwrite it before proceeding.
Another option is -n (no-clobber), which refuses to overwrite: mv -n report.txt ~/Documents/ will not move the file if something with that name is already there. This is safer if you want to make sure nothing gets deleted, but it means the move fails silently and you might not notice.
A third option is -b (backup), which creates a backup copy of the file being overwritten: mv -b report.txt ~/Documents/ moves the file and, if an old report.txt existed, renames the old one to report.txt~ so you still have it.
Understanding relative and absolute paths
When you type a destination, you can use either a relative path (relative to where you are now) or an absolute path (the full address from the root of the filesystem). A relative path does not start with a slash; an absolute path does.
For example, if you are in your home directory and you type mv report.txt Documents/, that is a relative path — Linux looks for a Documents folder inside your current location. If you type mv report.txt ~/Documents/, the tilde makes it absolute — Linux knows to look in your home directory no matter where you are. If you type mv report.txt /home/username/Documents/, that is also absolute — it uses the full filesystem path.
Relative paths are shorter to type when you are moving files within your home directory. Absolute paths are clearer and work the same way no matter which folder you are currently in, so they are useful in scripts or when you are working in unfamiliar parts of the filesystem.
Frequently Asked Questions
What is the difference between mv and cp?
cp copies a file, leaving the original in place. mv moves a file, removing it from the original location. If you want to keep the original and have a copy elsewhere, use cp. If you want to relocate the file and free up space, use mv.
Can I undo an mv command if I move the wrong file?
No — mv does not send files to a trash folder. Once you move a file, it is gone from the original location. If you moved it to the wrong place, you can move it back if you know where it went. If you deleted it by overwriting, it is usually not recoverable. This is why the -i flag is useful for important files.
How do I move a file with spaces in its name?
Put the filename in quotes: mv "my report.txt" ~/Documents/. Without quotes, Linux treats each word as a separate argument and the command fails. Alternatively, you can escape the space with a backslash: mv my\ report.txt ~/Documents/.
Can I move a file to a folder that does not exist yet?
No — mv will not create the destination folder for you. You must create it first using mkdir. For example, mkdir ~/Documents/archive creates the folder, then mv report.txt ~/Documents/archive/ moves the file into it.
What does the -v flag do?
The -v flag (verbose) makes mv print out what it is doing: mv -v report.txt ~/Documents/ will print something like "report.txt -> /home/username/Documents/report.txt" so you can see the move happened. This is useful when moving many files at once and you want confirmation.