Linux Second week study notes (6)
2.12.MV Command
MV command: Used to rename a file or directory, or to move a file from one directory to another.
---------------------------------------------------------------------------------------------
file name change: /tmp/ inside the directory 01.txt renamed to 01.1.txt
[Email protected] ~]# ls/tmp/
01.txt
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
Yum.log
[Email protected] ~]# cd/tmp/
[[email protected] tmp]# mv 01.txt 01.1.txt (Put 01.txt name changed to 01.1.txt )
[Email protected] tmp]# ls/tmp/
01.1.txt
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
---------------------------------------------------------------------------------------------
Move the file to another partition and change the name:
put /tmp/ under the directory 01.1.txt file moves to Root Partition and put 01.1.txt renamed to 02.txt
[[email protected] tmp]# ls
01.1.txt
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
[email protected] tmp]# MV 01.1.txt/root/02.txt (Put /tmp/ under the directory 01.1.txt file moves to Root Partition and put 01.1.txt renamed to 02.txt )
[[email protected] tmp]# ls
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
[Email protected] tmp]# ls/root/
02.txt anaconda-ks.cfg ( 01.1.txt has moved to /root/ directory and renamed to 02.txt )
---------------------------------------------------------------------------------------------
move the file to the directory: /tmp/ under the directory 11.txt file moves to /tmp/daizhihong/ directory under
[Email protected] tmp]# tree daizhihong/
daizhihong/
0 directories, 0 files
[[email protected] tmp]# ls
11.txt
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
Yum.log
[Email protected] tmp]# MV 11.txt daizhihong/
[[email protected] tmp]# ls
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
Yum.log
[Email protected] tmp]# tree daizhihong/
daizhihong/
└── 11.txt
0 directories, 1 file
-----------------------------------------------------------------------------------------------
" - I. "parameter: Before we use which when you query the absolute path of a command, a " - I. "parameter, the meaning of this parameter is a security parameter, ask whether the execution is because the added" - I. "The Parameters
[[email protected] tmp]# Touch 11.txt
[[email protected] tmp]# ls
11.txt
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
Yum.log
[Email protected] tmp]# MV 11.txt daizhihong/
MV : whether to overwrite "Daizhihong/11.txt" ? N(the "-i" parameter will prompt if you need to overwrite or delete the rm command, so "-I "is a safety parameter))
When typing a command, do not ask for the command format as follows:
[email protected] tmp]#/USR/BIN/MV 11.txt daizhihong/ Use
[Email protected] tmp]#
Absolute path command format execution will not prompt for an inquiry, directly overwrite
[[email protected] tmp]# ls
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
Yum.log
[[email protected] tmp]# ls Daizhihong
11.txt
-----------------------------------------------------------------------------------------
to move a directory: /tmp/daizhizhong1/ Directory moved to /tmp/daizhizhong/ directory, if the directory exists, the source file or directory will be moved to the directory
[[email protected] tmp]# ls
Daizhihong
Daizhihong1
Daizhihong3
Ks-script-9pf2we
[Email protected] tmp]# MV daizhihong1/daizhong/
[[email protected] tmp]# ls
Daizhihong
Daizhihong3
Daizhong
Ks-script-9pf2we
--------------------------------------------------------------------------------------------
When the directory is moved, the destination directory does not exist, and the source directory is named from the given destination file name
[[email protected] tmp]# ls
Daizhihong (source file)
Daizhihong3
Daizhong
Ks-script-9pf2we
Yum.log
[Email protected] tmp]# MV daizhihong/daizhihong2/
[[email protected] tmp]# ls
daizhihong2 (The source directory is named from the given destination file name)
Daizhihong3
Daizhong
Ks-script-9pf2we
Yum.log
-----------------------------------------------------------------------------------------
When the target directory exists at the time of movement, the original directory is placed under the target directory.
[[email protected] tmp]# ls
Daizhihong2
Daizhihong3
Daizhong
Ks-script-9pf2we
Yum.log
[Email protected] tmp]# MV daizhihong2/daizhong/
[[email protected] tmp]# ls
Daizhihong3
Daizhong
Ks-script-9pf2we
Yum.log
[[email protected] tmp]# ls daizhong/ ( target directory )
daizhihong daizhihong2 (original directory)
[Email protected] tmp]#
---------------------------------------------------------------------------------------------
When you move a directory, you will be asked if the directory exists to overwrite
[Email protected] tmp]# RM daizhhong/
RM: Cannot delete "daizhhong/": no file or directory
[Email protected] tmp]# mkdir Daizhihong
[email protected] tmp]# Touch daizhihong/01.txt
[Email protected] tmp]# tree daizhihong/
daizhihong/
└── 01.txt
0 directories, 1 file
[Email protected] tmp]# tree Daizhihong3
Daizhihong3
└── Daizhihong
└── 11.txt
1 directory, 1 file
[Email protected] tmp]# MV daizhihong/daizhihong3/
MV : whether to overwrite "Daizhihong3/daizhihong" ? y
MV: Unable to "daizhihong/" move to "Daizhihong3/daizhihong": file already exists
Linux Second week study notes (6)