Home » Linux » Basic Linux Commands » mv Linux Command

mv Linux Command

“mv” is a Linux command which is used to move files and directories from one location to another or to rename files.

The syntax of mv command is as below,


The options which can be passed with mv command are as below,

  • -v, –verbose explain what is being done
  • -f, –force do not prompt before overwriting
  • -i, –interactive prompt before overwrite
  • -n, –no-clobber do not overwrite an existing file

If we can look into some examples of using mv command,

Example 1 – Rename file or directory

$ mv file1.txt file2.txt

Above command is used to rename the file1.txt to file2.txt at same location. This can also work with directories as,

$ mv directory1 directory2

above command will rename the directory1 to directory2 if directory2 is not present, but if directory2 is present, then complete directory1 will be moved inside directory1, so mv or move command entirely depends upon what is the destination.

Example 2 – Move file / directory to another directory

$ mv file1.txt /home/user/

above command will move the file1.txt to /home/user directory. While moving please note, the source file will be deleted completely, if you want the source file to remain as is , use “cp” command.

Example 3 – Move all files from source to destination

$ mv /tmp/*.txt /home/user/

above command will copy all files with extention “.txt” from source directory /tmp to destination directory /home/user . The use of star “*” indicates all.

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment