Home >Operation and Maintenance >Linux Operation and Maintenance >linux move file command
linux move file command
mv command
Function: Rename a file or directory or move a file from one directory to another. This command is like the combination of ren and move under DOS.
Syntax: mv [options] Source file or directory Target file or directory
Description:
Depending on the type of the second parameter in the mv command (whether it is a target file or a directory target directory), the mv command renames the file or moves it to a new directory. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name). It will rename the given source file or directory to the given one. Target file name.
When the second parameter is an existing directory name, there can be multiple source files or directory parameters, and the mv command will move all the source files specified by each parameter to the target directory. When moving files across file systems, mv first copies and then deletes the original file, and the link to the file will also be lost.
Parameters:
- I Interactive operation. If the mv operation will cause the overwriting of an existing target file, the system will ask whether to rewrite and require the user to answer y or n, so as to avoid accidentally overwriting the file.
- f disables interactive operations. No instructions are given when the mv operation is to overwrite an existing target file. After specifying this option, the i option will no longer have any effect.
If the given target file (not the directory) already exists, the contents of the file will be overwritten by the new file. In order to prevent users from inadvertently destroying another file using the mv command, it is recommended that users use the i option when using the mv command to move files.
It should be noted that the results of mv and cp are different. mv seems to "move" the files, and the number of files does not increase, while cp copies the files, and the number of files increases.
Example 1: Move all files in /usr/xu to the current directory (indicated by "."):
$ mv /usr/xu/ * .
Example 2: Rename the file wch.txt to wjz .doc
$ mv wch.txt wjz.doc
Recommended related video tutorials: "Linux Tutorial"
The above is the detailed content of linux move file command. For more information, please follow other related articles on the PHP Chinese website!