The MV command is the abbreviation for move, which can be used to move files or rename files, which is also a common command, often used to back up files or directories.
1. Command format:
MV [option] source file or directory destination file or directory
2. Command function:
Depending on the second parameter in the MV command, which is the target file or the 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 rename, at which point the source file can only have one (or the source directory name), which renames the given source file or directory to the specified destination file name. When the second parameter is a directory name that already exists, the source file or directory parameter can have more than one, and the MV command moves the source files specified by each parameter to the destination directory. When you move a file across a file system, the MV copies the original file, and the link to the file is lost.
3. Command parameters:
-B Overwrite the previous backup if overwriting the file is required
-F Force mandatory meaning, if the target file already exists, will not ask and directly overwrite the-f parameter, mostly refers to the forces, simply do not say hello on the wall
-I if the target file destination already exists, it will ask whether to overwrite,-I, interactive, interactive. Sven's wall, generally you ask, there is no good results,
----It means yes when she says no.
-U if the target file exists and the source is newer, it will be updated,-u, update, updated
-T--target-directory=directory move all source arguments to directory, which is the target directory for the specified MV, which is suitable for moving multiple source files to a directory, at which point the target directory is in front, The source file is behind.
4. Command instance:
Instance one: File name
Command
MV Test.log test1.txt renamed Test.log file to Test1.txt file
Example two: Moving files
Command:
MV test1.txt test3 move test1.txt file to Test3, Test3 is a folder, don't ask me why
Example three: Move the file Log1.txt, Log2.txt, Log3.txt, to the directory test3.
MV Log1.txt log2.txt log3.txt test3 move log1.txt log2.txt log3.txt to Test3 folder
Mv-t/opt/soft/test/test4 log1.txt log2.txt log3.txt move log1.txt log2.txt log3.txt to/opt/soft/test/test4 Path
A directory in the back, a directory in front
Example four: Rename the file file1 to File2, if file2 already exists, ask whether to overwrite
Command:
Mv-i Log1.txt Log2.txt It will ask you, is it covered log2.txt?
Example five: The file name is renamed to File2, even if the file2 exists, it is also directly covered out.
Command:
Mv-f Log3.txt Log2.txt Whether or not log2.txt is already there, it will be covered by log3.txt
Example six: Moving a directory
Command:
MV Dir1 DIR2 If the directory Dir2 does not exist, rename the directory Dir1 to Dir2; otherwise, move Dir1 to Dir2
Example seven: Move all files under the current folder to the top level directory
Command:
MV *.. /* This asterisk is a wildcard character, matching any characters; /This is the parent directory
Example eight: Moving files in one subdirectory of the current directory to another subdirectory
Command:
MV Test3/*.txt TEST5
Example nine: file is overwritten before making a simple backup, preceded by parameter-B
MV Log1.txt-b Log2.txt
-B does not accept parameters, and MV will read the environment variable Version_control as a backup strategy.
--backup This option specifies a total of four backup strategies if the target file is present:
1.control=none or off unprepared
2.control=numbered or T-number backup
3.control=existing or nil: if there is a digitally numbered backup, continue numbering the backup M+1...N:
There is a digitally numbered file Log2.txt txt.~1~ before performing the MV operation, then this execution will produce log2.txt~2~, and so on. If there are no previously numbered files, use a simple backup that falls below.
4.control=simple or never: Use simple backup: A simple backup is made before being overwritten, a simple backup can only have one copy, and a simple backup will be overwritten when it is overwritten again.
One Linux command per day (--MV) command