Linux file and directory management: CP,MV,RM

Source: Internet
Author: User

When managing files and directories in Linux, CP (copy), MV (move), (remove) are the three most common commands, so what are the specific uses of these three commands?

Copy files or directories: CP

The main function of the CP command is to copy a file or directory whose command syntax is:

CP [OPTION] ... [-T] SOURCE DEST

CP [OPTION] ... SOURCE ... DIRECTORY

CP [OPTION] ...-t DIRECTORY SOURCE ...

As can be seen, for the CP command, the source file can be a single file, multiple files or directories, the target file can also be a file or directory, various types of source and target command execution results are as follows: 650) this.width=650; "Src=" http://s2.51cto.com/ Wyfs02/m00/85/20/wkiom1eapaebcwcoaabmw9k70fu268.png "title=" capture. PNG "alt=" Wkiom1eapaebcwcoaabmw9k70fu268.png "/>

Once you are familiar with the source-to-target match, take a look at some of the main options of the CP command:

-a,--archive: archive, equivalent to-DR--perserve=all

-D: equivalent to--no-dereference--perserve=links, even if source file is a linked file, copy the link file property instead of the original file itself

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/2A/wKiom1ebPuHRCzX3AAAh5VsGBMc601.png "title=" capture. PNG "alt=" Wkiom1ebpuhrczx3aaah5vsgbmc601.png "/>

-F,--Force: If the target file already exists and the overwrite cannot be opened, delete the destination file and try again

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/2A/wKioL1ebQgnB7TRtAAAkq10dQNo962.png "title=" Capture 1. PNG "alt=" Wkiol1ebqgnb7trtaaakq10dqno962.png "/>

-i,interactive: If the target file (destination) already exists, it will be asked before overwriting

-L,--Link: Create a linked file with hard links, rather than copying the file itself

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/2A/wKiom1ebRIPz_LiRAAAmDozz_6s176.png "title=" Capture 2. PNG "alt=" Wkiom1ebripz_liraaamdozz_6s176.png "/>

-P: Copy the past with the properties of the file instead of using the default properties (Backup common)

-r,-r,--Recursive: Recursive continuous replication for directory replication behavior

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/2A/wKioL1ebSALBCGPMAAA-FX3hpZg605.png "title=" Capture 4. PNG "alt=" Wkiol1ebsalbcgpmaaa-fx3hpzg605.png "/>

As you can see, the files and subdirectories under the source directory are copied to the destination directory during the copy of the directory.

- s,--symbolic-link: Copy into a symbolic link file (symbolic link), or "shortcut" file

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/2A/wKioL1ebRo6T19vwAAASLOcU83w981.png "title=" Capture 3. PNG "alt=" Wkiol1ebro6t19vwaaaslocu83w981.png "/>

- u,--update: Copy update if destination is missing than source old or destination destination

-V,--verbose: show command execution process

Move or rename a file: MV

The main function of the MV command is to move or rename the file (when the source file is in the same directory as the destination file, which is equivalent to renaming), whose command syntax is:

MV [OPTION] ... [-T] SOURCE DEST

MV [OPTION] ... SOURCE ... DIRECTORY

MV [OPTION] ...-t DIRECTORY SOURCE ...

As can be seen from the command syntax, the MV command and the CP command syntax is roughly the same, for various types of source and target command execution results, can refer to the CP command, will not repeat. Similarly, the MV command has some command options:

-F,--Force: If the target file already exists, it will not be queried and overwritten directly

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/2A/wKiom1ebTLDRivOHAAAXqZScv7E850.png "title=" Capture 5. PNG "alt=" Wkiom1ebtldrivohaaaxqzscv7e850.png "/>

-I,--Interactive: If the destination file (destination) already exists, you will be asked to overwrite

-N,--no-clobber: Do not overwrite files that already exist

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/2A/wKiom1ebTjTzhJ0jAAASsZnsyf0346.png "title=" Capture 6. PNG "alt=" Wkiom1ebtjtzhj0jaaassznsyf0346.png "/>

-U: If the target file already exists and source is newer, update (update)

-V,--verbose: show command execution process

Remove a file or directory: RM

The main function of the RM command is to remove a file or directory whose command syntax is:

RM [OPTION] ... FILE ...

For RM commands, there are also some command options:

- F,--Force: Forced delete, ignoring nonexistent files, no warning message

-I: Interactive mode, ask the user whether to operate before deleting

-R: Recursive deletion, commonly used for directory deletion

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/2A/wKioL1ebUCyg9IXfAAA6Tf1cCn4431.png "title=" Capture 7. PNG "alt=" Wkiol1ebucyg9ixfaaa6tf1ccn4431.png "/>

- v,--verbose: show command execution Process

Through the above narrative, we have a preliminary understanding of CP, MV, RM three commands, then the following questions should be how to solve it?

1, using the alias command, the daily/etc/directory of all files, backup to/testdir/under the new directory, and require the new directory format is BACKUPYYYY-MM-DD, the backup process is visible

[[email protected] ~]# alias xy= "Cp-avr/etc/testdir/backup ' Date +%f '"

[[email protected] ~]# alias XY

Alias xy= ' cp-avr/etc/testdir/backup2016-07-28 '

2, first create the/testdir/rootdir directory, and then copy all the files under/root to the directory, and require the retention of the original permissions

[Email protected] ~]# Cp-pr/root/testdir/rootdir


This article is from "Oscar winner" blog, please make sure to keep this source http://luoliumeng.blog.51cto.com/11882524/1831874

Linux file and directory management: CP,MV,RM

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.