Last Updated on May 22, 2022
mv
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/
Pages in this article:
Page 1 – cp
Page 2 – mv
Page 3 – rm
Page 4 – mkdir
All articles in this series:
Thanks. How many parts will this guide be?
We’re not certain of the final number of parts, but there’s plans for quite a few more. And we’re open to suggestions for additional areas that would help a beginner to Linux, or topics already covered where additional material would be welcome.