Simple Linux Command Line notes: MV

Source: Internet
Author: User
ArticleDirectory
    • Parameters
    • Option
    • Example
    • Tips

Rename, override, or move a file

MV [Options]Existing-file new-filename

MV [Options]Existing-file-List Directory

MV [Options]Existing-directory New-directory

 

Parameters

The first form:Existing-FileIs the file path to be renamed;New-filenameIs the new path name of the file for renaming or overwriting.

Second form:Existing-FileIs the list of file paths to be moved;DirectoryIs the new directory to be moved.

Third form:Existing-FileIs the directory path to be renamed;New-directoryIs the new path name of the directory for renaming or overwriting.

 

Option

-B. If the same file name already exists, back up the file before overwriting.

-F if the same file name already exists and the user does not have the write permission, forcibly Overwrite

-I if the same file name already exists, prompt the user to confirm before Overwriting

-U: Compare the modification time of the original and target files. If the target file is newer, it will not be overwritten.

-V: list all moved or renamed files

 

Example MV
 
$MVDemo1.txt demo2.txt $LsDemo2.txt

Rename a file

 

MV-I
 
$LsDemo2.txt demo.txt $MVDemo2.txt-I demo.txtMV: Overwrite?"Demo.txt"? Y

Confirm before overwriting an existing file. Strings starting with Y or y indicate OK, and other arbitrary characters indicate no.

 

The name of the file that does not have the write permission for the music video.
$ Ls - L total usage  0 -RW-r -- 1 Root 0 January 8   13 : 31   CC -RW-r -- 1 Siu 0 January 8  13 : 24   Dd  $  MV   Dd   CC  MV : Overwrite? "  CC  " And ignore the permission mode 0644 (RW-r -- )? Y $  Ls  CC 

Here, all CC users and groups are root, and my current user is Siu. During overwriting, confirmation is required.

 

MV-F does not have the write permission for the file name
$Ls-L total usage0-RW-r --1Root0January8 13:34AA-RW-r --1Siu0January8 13:34Bb $MVBb-F AA $LsAA

The same as above, but the-F option is added here, which is enforced during overwrite without prompting

 

MV Mobile Directory
$LsAbc cde $MVCde abc $LsABC $ CD ABC/$LsCDE

Move the CDE directory to the ABC directory.

MV rename directory
 
$LsABC $MVABCDir$LsDir

Rename the ABC directory to the Dir directory. Mv ABC ../You can move ABC to the parent directory.

 

MV-u
$Ls-L total usage0-RW-r --1Siu0January8 13:43Time1.txt-RW-r --1Siu0January8 13:44Time2.txt $MVTime1.txt-U time2.txt $LsTime1.txt time2.txt

Confirm that the modified time is overwritten again. The modified time of time2.txtis later than the modified time of time1.txt, so overwriting failed.

 

MV-V
 
$MVTime1.txt-V time2.txt"Time1.txt"->"Time2.txt"$LsTime2.txt

Lists information about moving or overwriting.

 

MV-B
 
$MV-B aa.txt bb.txt $LsBb.txt~

Backup is performed during overwriting. The backup file is at the end ~

 

Tips

1. in Linux, the concept of overwrite and rename is almost the same. There is no such concept as rename in windows.

2. You can write the option in any location, mv aa-v bb, MV-v aa bb, or mv aa bb-v.

 

 

 

 

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.