mv command

Moving or renaming files can be accomplished with the mv command.

Command: mv
Synopsis: mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE…

Options:
Below is a list of the options that can be used with the mv command. You can use more than one at a time by stacking them.

OptionLong NameDescription
–backup[=CONTROL]Make a backup of each existing destination file.
-bLike –backup but does not accept an argument.
-S-suffix=SUFFIXOverride the usual backup suffix./td>
-t–target-directory=DIRECTORYMove all SOURCE arguments into DIRECTORY
-T–no-target-directoryTreat DEST as a normal file.
-u–updatePerforms the move only when the SOURCE file is newer than the destination file or when the destination file is missing.
-v–verboseDisplays an explanation of what is being done.
–helpDisplay this help and exit.
–versionOutput version information and exit.

Examples

Renaming a file When renaming a file in the same directory, no directory information is included. The only parameters needed are the old and new file names. Below we rename the original oldtext.txt file to newtext.txt.

mv oldtext.txt newtext.txt

Moving a file to another directory In this example we are moving the file somefile.txt to a subfolder named level2. The second parameter includes the relative path as well as the file name.

mv somefile.txt level2/somefile.txt

Moving to another folder while renaming This example is much like the example above, but we are also renaming the file as it is moved. The second parameter includes the destination folder as well as the new name.

mv somefile.txt level2/newname.txt

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+