mv

Today's Command is "mv":


What will it do:

This command is used to rename files and directories; and to move files and directories from one place to another. Moving in this case refers to the act of copying something from one place to another and deleting the older original or source copy.

How to use it:

user@box ~$ mv foo bar

The above command will rename the file or directory named 'foo' in the user's home directory (~ is a an abbreviation for the home directory) to 'bar'.

user@box ~$ mv foo /tmp

The above command will move the file or directory named 'foo' in the user's home directory (~ is a an abbreviation for the home directory) to the '/tmp' directory.

Interestingly, one can combine the rename and move operations in a single command also. Here is how:

user@box ~$ mv foo /tmp/bar

Assuming that there is no file or directory named 'bar' in 'tmp', the above command will move 'foo' from the user's home directory to '/tmp' and rename it as 'bar'. In case there was a file named 'bar' in '/tmp' before, then it will be overwritten. If a directory named 'bar' was present in '/tmp' before then 'foo' would have been moved to '/tmp/bar' instead of '/tmp' (as shown in the second example) and no rename operation would have been performed.

Options

You can see the manual page for the various options by giving the following commands:

user@box $~ info mv
user@box $~ man mv