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.

Option Long Name Description
–backup[=CONTROL] Make a backup of each existing destination file.
-b Like –backup but does not accept an argument.
-S -suffix=SUFFIX Override the usual backup suffix./td>
-t –target-directory=DIRECTORY Move all SOURCE arguments into DIRECTORY
-T –no-target-directory Treat DEST as a normal file.
-u –update Performs the move only when the SOURCE file is newer than the destination file or when the destination file is missing.
-v –verbose Displays an explanation of what is being done.
–help Display this help and exit.
–version Output 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

Leave a Reply