learning linux command file directory command -mv command

mv command file can be used to move or rename the file (move (rename) files), are often used to back up a file or directory

Learn command

Format : mv [options] source file or directory target file or directory
command function : According to the mv command in the second parameter type (the target is the target file or directory), mv command to rename the file or move it to a new directory.
When the second argument is the file type, mv command to rename the file to complete, this time, only one source file (directory name may be a source), it will be given source file or directory rename given target file name.
When the second parameter is the name of the directory already exists, the source file or directory can have multiple parameters, mv command to specify the parameters of the source files are moved to the destination directory. When moving files across file systems, mv copies first, and then delete the original file, and chain link to the file will be lost.
Command parameters :
-b: For overwrite the file, before the first backup is overwritten.
-f: force the mandatory sense, if the target file already exists, do not ask directly covered
-i: If the target file (destination) already exists, it will ask whether to overwrite
-u: If the destination file already exists, compare and source new, will update (update)
-t: Specifies the destination directory mv this option is useful if moving multiple source files into a directory, in which case the previous target directory, the source file after.

Common examples

Example: rename a file
mv test.log test1.txt
test.log changed test1.txt

Example Two: moving files
Music Videos test1.txt test3
the test1.txt file to the directory test3

Example Three: The file log1.txt, log2.txt, log3.txt test3 moved to the directory.
mv log1.txt log2.txt log3.txt test3
will log1.txt, log2.txt, log3.txt test3 three files to a directory
mv -t / opt / soft / test / test4 / log1.txt log2.txt log3. txt
will move the three files to the directory test4

Example 5: The file was renamed file1 file2, even if file2 exists, but also cover direct swap.
mv -f log3.txt log2.txt

Example 6: To a mobile directory
Music Videos dir1 dir2
If dir2 directory does not exist, the directory dir1 renamed dir2; otherwise, moved into dir1 dir2

Example 7: move all current files in the folder to the parent directory
mv * ../

Example 8: put a subdirectory of the current directory in the file is moved to another subdirectory
mv test3 / * txt test5.

Original: Big Box  file linux command to learn the command directory command -mv


Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11652362.html