In this tutorial you will learn Linux mv command with useful examples Syntax: The move command is useful to rename SOURCE file to DEST file name. Also you can move a SOURCE file to other DIRECTORY. This command also allowed us to move DIRECTORY including all subdirectories to target directory.

mv Command Examples

Below is the basic mv command examples on Linux terminal.

mv Command Line Options

You must remember some of the command line options for mv command useful while working on terminal. You can also use -t option to provide destination directory.

-b Use this option to create a backup of each existing destination file. This is very useful from unwanted overwritten and data loss. If the destination file already exists it create a copy of destination file with ~ appended in file name.mv -b source.txt dest.txt -f, –force Use this option to overwrite destination file without prompting for the confirmation. This is useful for using mv command in automation tasks or shell scripts.mv -f source.txt dest.txt -i, –interactive This option is used to always prompt for confirmation before overwriting destination file.mv -i source.txt dest.txt cp: overwrite ‘dest’? Enter y/n option to allow or deny overwrite request. -t, –target-directory=DIRECTORY Use this option to move multiple files to destination directory.mv -t /tmp file1.txt file2.txt /opt/file3.txt The above command will move file1.txt, file2.txt and /opt/file3.txt files under the /tmp directory. -T, –no-target-directory If a directory at destination with same name already exists, then default command moves source file under the destination directory. This option instruct mv command to treat destination as file and stop moving source under the destination.mv -T source.txt output mv: cannot overwrite directory ‘output’ with non-directory -u, –update – This option tells mv command to move only if SOURCE file is newer than the destination file or the destination file is missing.mv -u source.txt dest.txt

Conclusion

In this tutorial, you have learned uses of Linux mv command with the useful examples and command line options. Please do share you thoughts about this article via comments to improve it. Your