mv Command in Linux: Move Files and Directories

When you need to reorganize directories, rename files in place, or move data between locations, the mv command is one of the fastest tools to use.
To move a file in Linux, use mv SOURCE DESTINATION. For example, mv file.txt /tmp/ moves file.txt into the /tmp directory.
The mv command (short for move) is used to move and rename files and directories from one location to another. This guide explains how to use the mv command with practical examples covering common options.
mv Command Syntax
The general syntax for the mv command is:
mv [OPTIONS] SOURCE DESTINATIONThe SOURCE can be one or more files or directories, and DESTINATION can be a single file or directory.
How mv behaves depends on the source and destination:
- If
SOURCEis a file andDESTINATIONis a directory, the file is moved into that directory. - If
SOURCEis a file andDESTINATIONis a file, the source is renamed to the destination. - If multiple files are given as
SOURCE, theDESTINATIONmust be a directory. - If
SOURCEis a directory andDESTINATIONdoes not exist,SOURCEis renamed toDESTINATION. IfDESTINATIONexists and is a directory,SOURCEis moved inside it.
To move a file or directory, you need write permissions on both the source and destination locations. Otherwise, you will receive a permission denied error.
Moving Files
To move a file from the current working directory to another directory:
mv file1 /tmpTo move a file and give it a new name at the destination:
mv file1 /tmp/newname.txtIf the file name starts with a dash (-), add -- before the source name so mv does not treat it as an option:
mv -- -file.txt /tmp/Renaming Files
To rename a file within the same directory, specify the new name as the destination:
mv file1 file2This renames file1 to file2 in the current directory.
Moving Directories
The syntax for moving directories is the same as for files. If dir2 exists, the command moves dir1 inside dir2. If dir2 does not exist, dir1 is renamed to dir2:
mv dir1 dir2Moving Multiple Files
To move multiple files, list them before the destination directory:
mv file1 file2 file3 dir1You can also use pattern matching. For example, to move all .pdf files to the ~/Documents directory:
mv *.pdf ~/DocumentsThe -t (target directory) option is useful when combining mv with other commands like find
:
find /tmp -name '*.log' -exec mv -t /var/log/archive {} +This moves all .log files found in /tmp to /var/log/archive.
-t option is supported by GNU mv (common on Linux). It is not available on some BSD or macOS systems.mv Command Options
The mv command accepts several options that affect its default behavior.
On some Linux distributions, mv is aliased
with default options. For example, some systems alias mv to mv -i. You can check whether mv is an alias using the type command:
type mvIf mv is aliased, the output will look like this:
mv is aliased to `mv -i'If conflicting options are given, the last one takes precedence.
Prompt Before Overwriting (-i)
By default, if the destination file exists, it is overwritten without warning. To prompt for confirmation, use the -i (interactive) option:
mv -i file1 /tmpmv: overwrite '/tmp/file1'?Type y to overwrite or n to skip.
Force Overwriting (-f)
When you try to overwrite a read-only file, mv prompts for confirmation by default:
mv: replace '/tmp/file1', overriding mode 0400 (r--------)?To skip the prompt and force the overwrite, use the -f option:
mv -f file1 /tmpThis option is useful when you need to overwrite multiple read-only files without being prompted for each one.
Do Not Overwrite (-n)
The -n option tells mv never to overwrite an existing file:
mv -n file1 /tmpIf file1 already exists in /tmp, the command does nothing. Otherwise, it moves the file.
Create Backups (-b)
If the destination file exists, you can create a backup of it before overwriting using the -b option:
mv -b file1 /tmpThe backup file has the same name as the original with a tilde (~) appended. Use the ls command
to verify:
ls /tmp/file1*/tmp/file1 /tmp/file1~To use a custom suffix instead of ~, use --suffix:
mv -b --suffix=.bak file1 /tmpThis creates a backup named file1.bak.
Verbose Output (-v)
The -v option prints the name of each file as it is moved:
mv -v file1 file2 /tmprenamed 'file1' -> '/tmp/file1'
renamed 'file2' -> '/tmp/file2'Moving Files Across Filesystems
When you move a file within the same filesystem, mv simply updates the directory entry without copying any data. This is nearly instant regardless of file size.
When you move a file to a different filesystem (for example, from your hard drive to a USB drive), mv copies the file to the destination and then deletes the original. This takes longer for large files and means the move is not atomic. If the process is interrupted, the file may exist in both locations or be incomplete at the destination.
Troubleshooting
mv: cannot stat 'file': No such file or directory
The source path is incorrect or the file has already been moved. Verify the path with ls and quote paths that contain spaces.
mv: cannot move ...: Permission denied
You do not have write permissions on the source or destination directory. Check permissions with ls -ld and use sudo only when required.
Move across filesystems was interrupted
When moving across filesystems, mv copies data and then removes the source. If interrupted, verify both source and destination paths before deleting anything manually.
mv: target 'dir' is not a directory
This happens when you pass multiple source files and the destination does not exist as a directory. Create the destination directory first or pass a single source file.
Quick Reference
For a printable quick reference, see the mv cheatsheet .
| Command | Description |
|---|---|
mv file1 /tmp | Move a file to a directory |
mv file1 file2 | Rename a file |
mv dir1 dir2 | Move or rename a directory |
mv file1 file2 dir/ | Move multiple files to a directory |
mv *.txt dir/ | Move files matching a pattern |
mv -i file1 /tmp | Prompt before overwriting |
mv -f file1 /tmp | Force overwrite without prompting |
mv -n file1 /tmp | Do not overwrite existing files |
mv -b file1 /tmp | Create backup of destination before overwriting |
mv -v file1 /tmp | Print each file as it is moved |
mv -t dir/ file1 file2 | Specify target directory first |
FAQ
What is the difference between mv and cp?mv moves or renames a file, and the original is removed from its source location. cp creates a copy, leaving the original in place.
Does mv preserve file permissions and timestamps?
Yes. When moving within the same filesystem, mv preserves all metadata. When moving across filesystems, mv copies the file and attempts to preserve permissions, ownership, and timestamps.
How do I move hidden files (dotfiles)?
The glob * does not match hidden files by default. Use mv .[!.]* ..?* /destination/ to move dotfiles safely, or use shopt -s dotglob in Bash to include dotfiles in glob patterns.
How do I move a file without overwriting the destination?
Use the -n option: mv -n file1 /tmp. If the destination file already exists, mv does nothing.
Can I undo a mv command?
No. The mv command does not have an undo feature. If you used -b, you can restore the backup file manually. Otherwise, you must move the file back to its original location yourself.
Conclusion
Use mv for moves and renames, add -i or -n when overwrites are possible, and use cp when you need to keep the original file.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page