mv Command in Linux

Back

While you can't rename a file in Linux, you can move it. The mv command essentially puts a different label on files.

For example :

The mv file1 file2 command changes the name of file1 to file2. Unless you are moving the file to different partition, everything about the file , including the i-node number, remains the same. The mv command works with directories too.

Syntax:

mv [-f] [-i] oldname newname

-f mv will move the file(s) without prompting even if it is writing over an existing target. Note that this is the default if the standard input is not a terminal.

-i Prompts before overwriting another file.
oldname The oldname of the file renaming.
newname The newname of the file renaming.
filename The name of the file you want to move directory - The directory of were you want the file to go.


$ mv oldname newname

$ mv filename /dest/di

$ mv oldDir newDir
$ mv letters letters.old