- Published on
mv command-move or rename files
Jonas
The mv command is an abbreviation of the word "move", and its function is roughly the same as the English meaning. You can move files or rename them.
This is a very frequently used file management command, we need to pay special attention to the difference between it and copy: the results of mv and cp are different. The mv command seems to "move" the file, the file name has changed, but the number has not increased. The cp command is to copy files, and the number of files is increased.
Syntax: mv [parameter]
Command parameters
-i | If a file with the same name exists, ask the user whether to overwrite |
-f | No prompt will be given when overwriting existing files |
-b | When the file exists, create a backup for it before overwriting |
-u | When the source file is newer than the target file, or the target file does not exist, move this operation |
Example
Rename the file file_1 to file_2:
[root@linuxstar ~]# mv file_1 file_2
Move the file file to the directory dir:
[root@linuxstar ~]# mv file /dir
Move the directory dir1 to the directory dir2 (provided that the directory dir2 already exists, if it does not exist, rename it):
[root@linuxstar ~]# mv /dir1 /dir2
Move the files in the directory dir1 to the current directory:
[root@linuxstar ~]# mv /dir1/*.