Introduction to MV Command:
The MV command is the abbreviation for move, which can be used to move files or rename files (rename), which is a common command under Linux, 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 type in the MV command (either the destination file or the destination 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 you need to overwrite the file.
-f:force if the target file already exists, does not ask to directly force the overwrite;
-I: If the target file (destination) already exists, you will be asked to overwrite it!
-U : if the target file already exists and source is newer, update (update)
-T,--target-directory=directory :
Move all SOURCE arguments to DIRECTORY
This option is useful when moving multiple source files to a directory, when the destination directory is in front of the source file.
4. Command instance:
Example one: Renaming a file
Command:
MV Test.log Test1.txt
Description
the file Test.log Rename to Test1.txt
Example two: Moving files, renaming under the same directory
Command:
MV Test1.txt Test3
Description:
will be Test1.txt file move to directory test3 in
Example Three: the file Log1.txt , Log2.txt,log3.txt Move to Directory test3 the.
Command:
MV Log1.txt Log2.txt Log3.txt test3
mv-t/opt/soft/test/test4/log1.txt log2.txt Log3.txt
Description:
mv log1.txt log2.txt log3.txt test3 command Span style= "font-size:14px;font-family: ' Times New Roman ';" >log1.txt three files moved to test3 directory,
mv-t/opt/soft/test/test4/log1.txt log2.txt log3.txt command to move three files to a test4 directory to go
Example four: Rename the file file1 to File2, if file2 already exists, ask whether to overwrite
Command:
Mv-i Log1.txt Log2.txt
Example Five: mv-f the file file1 renamed to File2, even if file2 exists, it is also directly covered out.
Command:
Mv-f Log3.txt Log2.txt
Description:
Log3.txt content is directly covered by the log2.txt content,-f It's a dangerous option,
Always keep your mind clear when you use it, and generally It's best not to add it.
Example six: Moving a directory
Command:
MV Dir1 Dir2
Description:
If the directory Dir2 does not exist, rename the directory Dir1 to Dir2, and if the directory Dir2 exists , move Dir1 to Dir2.
Example 7: Move all files under the current folder to the top level directory
Command:
MV *.. /
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
Command:
MV Log1.txt-b Log2.txt
Output:
[[email protected] TEST5] # ll
-rw-r--r--1 root root 10-28 07:02 Log1.txt
-rw-r--r--1 root root 10-28 06:16 Log2.txt
[Root@localhost Test5] # MV Log1.txt-b Log2.txt
Mv:overwrite ' 3/RC5 '? Y
[Root@localhost Test5] # ll
-rw-r--r--1 root root 10-28 07:02 Log2.txt
-rw-r--r--1 root root 10-28 06:16 log2.txt~ ***
Description
- b parameters are not accepted, The 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: not backed up.
2.control=numbered or T: Digitally numbered backup
3.control=existing or nil: if there is a digitally numbered backup, continue numbering the backup M+1...N:
a digitally numbered file already exists before performing the MV Operation log2 . txt.~1~, then re-execution will produce log2 . txt~2~, to the second analogy. If you don't have a digitally numbered file before, use the simple backup described 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.
Linux commands: MV