Last Updated on May 22, 2022
mv is a command to move or rename files and directories. It either moves one or more files to a different directory, or it will rename a file or directory.
With the command below we are renaming the filename source to the filename target. If target does not exist then source is renamed target. If target exists its contents are silently replaced with the contents of source.
$ mv source target
Let’s move 3 files into a different directory, keeping the filenames:
$ mv source1 source2 source3 target_directory
If we want to prevent accidentally overwriting files, we can prompt for confirmation before overwriting existing files, regardless of file permissions with:
$ mv -i source target
Here’s a few other examples of common mv usage.
Do not overwrite existing files at the target:
$ mv -n source target
Move files in verbose mode, showing files after they are moved:
$ mv -v source target
Like cp, the power of mv is enhanced with wildcards. For example, let’s suppose we want to move image files (.jpg and .png) to our Pictures directory.
$ mv *.jpg *.png ~/Pictures/
All articles in this series: