1. Function: Move the file or modify the name of the file
2. Usage: MV [option] source file destination file or source file destination directory
3. Parameters:
-B,--Backup[=control] to back up existing files
-F,--force forced override
-I,--interactive if the target file exists, ask whether to overwrite
-N,--no-clobber does not allow overwriting
-T,--target-directory=directory to move all source files to the target directory
-T,--no-target-directory the target file as a normal file
-U,--update can only be moved if the source file is newer than the target file
4. Example
Example 1: Renaming a test_1.txt file to Test_mv.txt
[[email protected] home]# CD test
[[email protected] test]# ls
Test_1 Test_1.txt Test_monday.txt
[email protected] test]# mv Test_1.txt test_mv.txt
[[email protected] test]# ls
Test_1 Test_monday.txt Test_mv.txt
Example 2: With the-b parameter, when you modify the name of the Test_1.txt, Test_mv.txt is named test_mv.txt~, overwriting the file before asking whether to overwrite
[[email protected] test]# ls
Test_1 Test_1.txt Test_mv.txt
[email protected] test]# mv-b test_1.txt test_mv.txt
MV: Do you want to overwrite "Test_mv.txt"? Y
[[email protected] test]# ls
Test_1 test_mv.txt test_mv.txt~
Example 3: Forcing overwrite Test_mv.txt
[[email protected] test]# ls
Test_1 Test_1.txt Test_mv.txt
[email protected] test]# mv-f test_1.txt test_mv.txt
[[email protected] test]# ls
Test_1 Test_mv.txt
Example 4: With the-n parameter, does not allow overwriting the file, does not report an error
[email protected] test]# mv-n test_1.txt test_mv.txt
[[email protected] test]# ls
Test_1 test_1.txt test_2.txt Test_mv.txt
Example 5: Copy the test_* file to the/test_1 folder
[[email protected] test]# ls
Test_1 test_1.txt test_2.txt Test_3.txt
[email protected] test]# mv-t test_1 test_*.txt
[[email protected] test]# ls
Test_1
[email protected] test]# CD test_1/
[[email protected] test_1]# ls
Test_1.txt test_2 test_2.txt Test_3.txt
Example 6: Update a file with the-u parameter, Test_1.txt time earlier than Test_mv.txt, cannot be overwritten, Test_2.txt time is later than Test_mv.txt, you can overwrite it.
[email protected] test]# ls-lh
Total dosage 16K
Drwxr-xr-x 3 root root 4.0K May 18:09 test_1
-rw-r--r--1 root root 16 May 18:00 Test_1.txt
-rw-r--r--1 root root 16 May 18:12 Test_2.txt
-rw-r--r--1 root root 16 May 18:10 Test_mv.txt
[email protected] test]# mv-u test_1.txt test_mv.txt #未报错, not covered
[email protected] test]# ls-lh
Total dosage 16K
Drwxr-xr-x 3 root root 4.0K May 18:09 test_1
-rw-r--r--1 root root 16 May 18:00 Test_1.txt
-rw-r--r--1 root root 16 May 18:12 Test_2.txt
-rw-r--r--1 root root 16 May 18:10 Test_mv.txt
[email protected] test]# mv-u test_2.txt test_mv.txt
MV: Do you want to overwrite "Test_mv.txt"? Y
[email protected] test]# ls-lh
Total dosage 12K
Drwxr-xr-x 3 root root 4.0K May 18:09 test_1
-rw-r--r--1 root root 16 May 18:00 Test_1.txt
-rw-r--r--1 root root 16 May 18:12 Test_mv.txt
Linux Common Commands Summary-mv