mv: move and rename files
mv moves files and directories to another place, or renames them. Unix has no separate rename command for single files: renaming is just moving to a new name.
mv [options] source target
mv [options] source ... directory
Common options
| Option | Meaning |
|---|---|
-i | Ask before overwriting |
-n | Never overwrite |
-v | Show what is moved |
-b | Keep a backup of an overwritten file (GNU) |
-t dir | Move everything into dir (GNU; useful with xargs) |
Examples
mv draft.txt final.txt # rename
mv final.txt ~/Documents/ # move into a directory
mv *.log old-logs/ # move many files
mv -i new.conf /etc/app/app.conf # ask before replacing
mv project project-2025 # rename a directory
mv -- -strange-name.txt normal.txt # a name starting with "-": end options with --
Renaming many files
mv renames one file at a time. For bulk renames, use a loop or the rename tool:
# change the extension of every .jpeg file to .jpg
for f in *.jpeg; do mv -- "$f" "${f%.jpeg}.jpg"; done
# with the Perl rename (Debian/Ubuntu package "rename"); -n shows what would happen
rename -n 's/ /_/g' * # replace spaces with underscores
rename 's/ /_/g' *
On RHEL and Fedora, the default rename command is a simpler util-linux tool with different syntax: rename .jpeg .jpg *.jpeg.
Things to know
- Within one file system,
mvis instant: only the directory entry changes. Between file systems it copies and then deletes, which takes time and needs space on the target. mvoverwrites the target without asking unless you use-ior-n.- To move a directory you need write permission on both the old and the new parent directory.