Linux mv command is used to move or rename files. We generally provide the source and destination files and directories to mv
command.
mv Command Syntax
The Linux mv command has the following simple syntax where SOURCE and DESTINATION are a must.
mv [OPTION]... SOURCE... DESTINATION
- SOURCE is the source file or directory which will be moved to the DESTINATION
- DESTINATION is the destination file or folder which will be moved from the SOURCE
- OPTION is used to change provides different behavior for the mv command and optional by default.
Move File or Folder
The regular usage of mv
command is moving files or directories. We will provide source files or directory and destination file or directory. In this example, we will move or rename directory named backup
into live
.
$ mv backup live
Force Moving File or Folder
If there are files and folders in the destination the mv command will stop moving. We can force move operation with -f
option.
$ mv -f backup live
Ask Before Overwrite
We can prompt before overwriting the destination file. We will use -i
option for this. In order to accept overwrite we should answer with y
or Y
.
$ mv -i backup live
Verbose Mode – Print Every Move Operation
While moving files we may need to list all moved files. We call this verbose
mode. This will list moved files line by line with -v
option like below.
$ mv -v backup live