mv(1)
Move or rename files and directories.
Synopsis
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... SOURCE DESTDescription
Renames SOURCE to DEST, or moves SOURCE(s) into DIRECTORY. If DEST is an existing directory, mv moves each SOURCE into that directory. Otherwise, mv renames the final SOURCE to DEST.
By default, mv overwrites existing destination files without prompting. Use -i to enable interactive mode.
Common options
| Flag | What it does |
|---|---|
-i | Prompt before overwriting existing files |
-f | Force overwrite without prompting (default behavior) |
-n | Do not overwrite existing files; silently skip |
-v | Verbose; print each file being moved |
-u | Only move if SOURCE is newer than DEST or DEST is missing |
--backup=simple | Back up existing destination files with ~ suffix |
-b | Make backup of existing destination files (shorthand for --backup) |
--no-clobber | Do not overwrite existing files (same as -n) |
Examples
Rename file from old.txt to new.txt in the same directory
mv old.txt new.txtMove file.txt into the Documents directory in home folder
mv file.txt ~/Documents/Move all .log files from current directory to /var/log/
mv *.log /var/log/Rename file.txt to existing.txt; prompt before overwriting if existing.txt exists
mv -i file.txt existing.txtMove directory dir1 into dir2 with verbose output showing the action
mv -v dir1 dir2Move old_data.csv only if it's newer than the file in backup directory
mv -u old_data.csv ~/backup/Rename file.txt to file.txt.bak, backing up any existing file.txt.bak as file.txt.bak~
mv -b file.txt file.txt.bakMove all .txt files to archive directory without overwriting existing files
mv -n *.txt /archive/