mv Command
Beginner File Management man(1)Move or rename files and directories
👁 10 views
📅 Updated: Mar 15, 2026
SYNTAX
mv [OPTION]... SOURCE... DESTINATION
What Does mv Do?
The mv command moves files and directories from one location to another, or renames them. Unlike cp, mv does not create a copy — it relocates the original file.
When moving files within the same filesystem, mv simply updates the directory entry, making it nearly instantaneous regardless of file size. When moving across filesystems, mv performs a copy followed by deletion of the original.
mv is also the standard way to rename files and directories in Linux, since there is no dedicated rename command in the core utilities.
When moving files within the same filesystem, mv simply updates the directory entry, making it nearly instantaneous regardless of file size. When moving across filesystems, mv performs a copy followed by deletion of the original.
mv is also the standard way to rename files and directories in Linux, since there is no dedicated rename command in the core utilities.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -i | Interactive - prompt before overwriting | mv -i old.txt new.txt |
| -f | Force - do not prompt before overwriting | mv -f temp.log /var/log/ |
| -n | Do not overwrite existing files | mv -n src.txt dest.txt |
| -v | Verbose - explain what is being done | mv -v *.jpg /photos/ |
| -u | Move only when source is newer than destination | mv -u *.log /archive/ |
| --backup | Make a backup of existing destination files | mv --backup=numbered file.txt /dest/ |
Practical Examples
#1 Rename a file
Renames the file in the current directory.
$ mv oldname.txt newname.txt#2 Move file to another directory
Moves the file to Documents, removing it from the current location.
$ mv report.pdf /home/user/Documents/#3 Move multiple files
Moves all JPEG and PNG files to the Pictures directory.
$ mv *.jpg *.png /home/user/Pictures/#4 Rename a directory
Renames a directory. No -r flag needed unlike cp.
$ mv old-project/ new-project/#5 Move with verbose output
Shows each file being moved.
$ mv -v /tmp/downloads/* /home/user/Downloads/
Output:
renamed '/tmp/downloads/file1.zip' -> '/home/user/Downloads/file1.zip'
renamed '/tmp/downloads/file2.tar.gz' -> '/home/user/Downloads/file2.tar.gz'
#6 Safe move with backup
Creates numbered backups if destination exists (config.yml.~1~, config.yml.~2~).
$ mv --backup=numbered config.yml /etc/app/Tips & Best Practices
No undo: mv has no undo operation. If you overwrite a file, it is gone. Always use -i for important files.
Batch rename: For batch renaming, use the "rename" command (perl-based): rename "s/old/new/" *.txt
Cross-filesystem moves: Moving files across filesystems (e.g., from /home to /tmp on different partitions) is slower because mv must copy then delete.
Frequently Asked Questions
How do I rename a file in Linux?
Use mv: mv oldname.txt newname.txt. This is the standard way to rename files in Linux.
Can mv move directories?
Yes! Unlike cp, mv does not need the -r flag for directories. Just use: mv source_dir/ destination_dir/
How do I move files without overwriting?
Use mv -n (no-clobber) to skip existing files, or mv -i for interactive prompts before each overwrite.
Related Commands
More File Management Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →