mv
Quick Reference
Command Name:
mv
Category:
file management
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
- 1
File renaming
Change filenames quickly while preserving all file attributes
- 2
File organization
Relocate files to more appropriate directories
- 3
Batch processing
Move processed files to archive or completed directories
- 4
Directory restructuring
Reorganize directory hierarchies without copying data
Syntax
mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE...
Options
Option | Description |
---|---|
--backup[=CONTROL] | Make a backup of each existing destination file |
-b | Like --backup but does not accept an argument |
-f, --force | Do not prompt before overwriting |
-i, --interactive | Prompt before overwrite |
-n, --no-clobber | Do not overwrite an existing file |
--strip-trailing-slashes | Remove trailing slashes from each SOURCE argument |
-S, --suffix=SUFFIX | Override the usual backup suffix |
-t, --target-directory=DIRECTORY | Move all SOURCE arguments into DIRECTORY |
-T, --no-target-directory | Treat DEST as a normal file |
-u, --update | Move only when the SOURCE file is newer than the destination file or when the destination file is missing |
-v, --verbose | Explain what is being done |
-Z, --context | Set SELinux security context of destination file to default type |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the mv
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
mv file.txt newname.txt
Rename file.txt to newname.txt in the current directory.
mv file.txt /path/to/directory/
Move file.txt to another directory.
mv file1.txt file2.txt destination/
Move multiple files to a directory.
Advanced Examples:
mv -i important.txt /backup/
Interactive mode: prompt before overwriting an existing file.
mv -n file.txt /data/
No-clobber: do not overwrite an existing file.
mv -v *.txt /archive/
Verbose mode: explain what is being done.