Linux Step---MV command

Source: Internet
Author: User

1 command function (brief description):

Commands can be used to move files or change file names, often used to back up files or directories, MV--and move

2 Command syntax:

MV "option" "Source file or directory name" "Target file or directory name" #注: "" is not required option

3 command options (only common command parameters are described):

Use the help command: Man mkdir or Mkdir-help

--backup[=control] Create a backup for each existing target file
-B similar to--backup but does not accept parameters
-F,--force does not ask before overwriting, if the target file already exists, does not ask and directly overwrite.
-I,--interactive when the target file already exists in the current directory, it will be queried before overwriting.
-N,--no-clobber does not overwrite existing files if you specify multiple in-I,-F,-N, only the last one takes effect.
--strip-trailing-slashes remove the trailing slash of each source file parameter
-S,--suffix=suffix replace the common backup file suffix
-T,--target-directory=directory moves the source file or directory specified by all parameters to the specified directory, which is useful for moving multiple source files to a directory, noting that the target directory is in front of each source file after
-T,--no-target-directory to treat the target file as normal file processing
-U,--update only moves when the source file is newer than the destination file or the destination file does not exist

4 Usage Examples:

 (1) Change of MV file name

[[email protected] command_test] # ls av.log[root@localhost command_test] # MV Av.log Av.mp4 [[email protected] command_test] # ls av.mp4[root@localhost command_test] #

 (2) MV "file name or directory" "file name or directory"------move files

#first create the directory Dir1[[email protected] command_test]#mkdir dir[[email protected] command_test]#llTotal dosage 4-rw-r--r--. 1 root root 0 July 26 23:27AV.MP4DRWXR-xr-x. 2 root root 4096 July 26 23:35Dir1[root@localhost Command_test]# #Create the test file Canglaoshi.txt and move the file to the Dir1 directory[[email protected] command_test]#Touch Canglaoshi.txt[[email protected] command_test]#lsav.mp4 canglaoshi.txt dir1[root@localhost Command_test]#MV Canglaoshi.txt Dir1[[email protected] command_test]#lsAv.mp4 Dir1[root@localhost Command_test]# #Create Canglaoshi.txt because the Canglaoshi.txt file in the previous step already exists in the Dir1 directory, continue to move the file to Dir1 equivalent to overwrite operation, before overwriting will ask[[email protected] command_test]#Touch Canglaoshi.txt[[email protected] command_test]#lsav.mp4 canglaoshi.txt dir1[root@localhost Command_test]#MV Canglaoshi.txt Dir1MV: whether to overwrite"Dir1/canglaoshi.txt"? Y[root@localhost Command_test]#lsAv.mp4 Dir1[root@localhost Command_test]# #Create Canglaoshi.txt again, this time try the-F parameter to force the move file, ignoring whether the target directory already exists directory, overwriting does not ask[[email protected] command_test]#Touch Canglaoshi.txt[[email protected] command_test]#lsav.mp4 canglaoshi.txt dir1[root@localhost Command_test]#mv-f canglaoshi.txt Dir1[[email protected] command_test]#lsAv.mp4 Dir1[root@localhost Command_test]#

  (3) MV "File 1" "File 2" "File 3" "Target directory"-------multiple files to the same directory, note the difference of-t parameter effect

#First we create the files and directories Dir1[[email protected] command_test]#Touche canglaoshi.txt xioacang.txt boduo.txt-Bash:touche:command not Found[root@localhost Command_test]#Touch canglaoshi.txt xioacang.txt boduo.txt[[email protected] command_test]#lsboduo.txt canglaoshi.txt xioacang.txt[root@localhost Command_test]#mkdir Dir1[[email protected] command_test]#lsboduo.txt canglaoshi.txt dir1 xioacang.txt#Note the MV command when moving multiple files, the last parameter is a target directory that already exists, otherwise an error occurs[[email protected] command_test]#mv Boduo.txt canglaoshi.txt xioacang.txt dir1[[email protected] command_test]#lsDir1[root@localhost Command_test]#CD Dir1[[email protected] dir1]#lsboduo.txt canglaoshi.txt xioacang.txt[root@localhost Dir1]# #The following example shows the same move for multiple files, but one thing is, the MV command uses the-t parameter, you need to put the target directory first, followed by the need to move a number of files[[email protected] command_test]#pwd/home/Command_test[root@localhost Command_test]#lsDir1[root@localhost Command_test]#CD Dir1[[email protected] dir1]#lsboduo.txt canglaoshi.txt xioacang.txt[root@localhost Dir1]#mv-t/home/command_test boduo.txt canglaoshi.txt xioacang.txt[[email protected] dir1]#ls[[email protected] dir1]#[[email protected] dir1]#CD..[[email protected] command_test]#lsboduo.txt canglaoshi.txt dir1 xioacang.txt[root@localhost Command_test]# 

  (4) Movement of MV Directory

#Create two levels of two directories and move the directory Dir1 and its subdirectories to DIR3, which is easy to move through[[email protected] command_test]#mkdir-p Dir1/dir2[[email protected] command_test]#mkdir-p DIR3/DIR4[[email protected] command_test]#lsDir1 dir3[root@localhost Command_test]#MV Dir1 Dir3[[email protected] command_test]#lsDir3[root@localhost Command_test]#CD Dir3[[email protected] dir3]#lsDir1 dir4[root@localhost Dir3]#CD Dir1[[email protected] dir1]#lsDir2[root@localhost Dir1]# 

  (5) MV Use relative path to move directory to the top level directory

#use relative paths to move everything under the current directory to the top level directory[[email protected] command_test]#mkdir Dir1[[email protected] command_test]#lsDir1[root@localhost Command_test]#CD Dir1[[email protected] dir1]#Touch Canglaoshi.txt Xiaocang.txt[[email protected] dir1]#lscanglaoshi.txt Xiaocang.txt[root@localhost Dir1]#MV *.. /[[email protected] dir1]#ls[[email protected] dir1]#CD..[[email protected] command_test]#lscanglaoshi.txt Dir1 xiaocang.txt[root@localhost Command_test]# 

  

Linux Step---MV command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.