$linuxjunkies
>

mv(1)

Move or rename files and directories.

UbuntuDebianFedoraArch

Synopsis

mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... SOURCE DEST

Description

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

FlagWhat it does
-iPrompt before overwriting existing files
-fForce overwrite without prompting (default behavior)
-nDo not overwrite existing files; silently skip
-vVerbose; print each file being moved
-uOnly move if SOURCE is newer than DEST or DEST is missing
--backup=simpleBack up existing destination files with ~ suffix
-bMake backup of existing destination files (shorthand for --backup)
--no-clobberDo not overwrite existing files (same as -n)

Examples

Rename file from old.txt to new.txt in the same directory

mv old.txt new.txt

Move 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.txt

Move directory dir1 into dir2 with verbose output showing the action

mv -v dir1 dir2

Move 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.bak

Move all .txt files to archive directory without overwriting existing files

mv -n *.txt /archive/

Related commands