CP commands in Linux & old nine gates

Source: Internet
Author: User


CP Command Detailed

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/85/3A/wKioL1edjenimOL6AADtBqoIns0201.jpg "title=" 1.jpg " alt= "Wkiol1edjenimol6aadtbqoins0201.jpg"/>


Old Nine gate of CP command


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/3A/wKioL1edjenCIGF5AAGL-lXHY28795.png "title=" 2.png " alt= "Wkiol1edjencigf5aagl-lxhy28795.png"/>


Let's look at the first case:

1, the source is a file, the goal is not exist

Using CP Aa/testdir/dir1 He will create a Dir1 target file and place the source content in the dir target file created

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/3A/wKiom1edjenQYk4DAABCfEF5Ck4595.png "title=" 3.png " alt= "Wkiom1edjenqyk4daabcfef5ck4595.png"/>


2, the source is a file, the target exists and is a file (the above command executes, Dir1 file will be created), and then execute the CP Aa/testdir/dir1 again, will prompt you whether to overwrite dir1 this file, select Y, Looking again at the properties of the AA and Dir1 files, I found that the Dir1 Mtime changed and the file was modified, and indeed the copy was completed.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/3A/wKiom1edjemSG7oLAABJBnlkXTc633.png "title=" 4.png " alt= "Wkiom1edjemsg7olaabjbnlkxtc633.png"/>

But using the same command to log in to a terminal with a normal user, there is no such interactive reminder that the root user defines an alias that takes advantage of the-i option of the CP command, when we look at the definition of the alias to find the alias.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/3A/wKioL1edjeqCo-rvAAArsGqFCX4947.png "title=" 5.png " alt= "Wkiol1edjeqco-rvaaarsgqfcx4947.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/3A/wKioL1edjeryczIZAAA5Ae0a6AM750.png "title=" 6.png " alt= "Wkiol1edjeryczizaaa5ae0a6am750.png"/>

At this point under the root user, I do not want to have interactive prompts, can be executed by the command itself, there are three ways

1. \CP Anti-slash CP

2, ' CP ' single quote CP

3,/USR/BIN/CP use absolute path


Use of the-f option

The root user now copies/testdir/aa to the Andy user's home directory and is named after DD

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/3A/wKiom1edjerxUWk0AAANfLG0sqQ301.png "title=" 7.png " alt= "Wkiom1edjerxuwk0aaanflg0sqq301.png"/>

At this point we re-open a terminal, using the Andy User login, see the home directory below the file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/3A/wKioL1edjeqi7wQ-AAAqmpFe2YA749.png "title=" 8.png " alt= "Wkiol1edjeqi7wq-aaaqmpfe2ya749.png"/>

The owners and groups of the DD files are found to be root users, which we will not be surprised to maintain the original attributes

At this time using the CP AA DD command to see if the DD file can be overwritten, found that the permissions are not enough

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKiom1edjerQKuy_AAAVW1EcOkU586.png "title=" 9.png " alt= "Wkiom1edjerqkuy_aaavw1ecoku586.png"/>

at this time using CP-F AA DD implementation is to delete the DD file first, and then in the Andy user to create a DD file, and the contents of the AA file is written into the DD ( Why is the original DD file deleted?) We see the new DD file of the owner and the group will know, if it is not deleted DD file, simple to perform the overwrite operation, its DD original owner and group attributes are not changed ) by checking man help is also the same meaning

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKioL1edjevhcKdVAAAZu0HWZpA843.png "title=" 10.png "alt=" Wkiol1edjevhckdvaaazu0hwzpa843.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/3A/wKiom1edjeuTeDLRAACT8AqrZh8539.png "title=" 11.png "alt=" Wkiom1edjeutedlraact8aqrzh8539.png "/>


3. source is a file, the destination exists and is a directory

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/3A/wKiom1edjeuSsp_IAAAmdvZIEBc481.png "title=" 12.png "alt=" Wkiom1edjeussp_iaaamdvziebc481.png "/>

using the CP aa/home/Command (note the spelling of the directory), a file with the same name as AA is created under the target/home/directory and the contents of the source file are written to the file created in the home directory


4, the source is multiple files, the target is a file and does not exist

The error will not be executed at this time

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/3A/wKioL1edjeui5WlIAAAn1MdGc-M857.png "title=" 13.png "alt=" Wkiol1edjeui5wliaaan1mdgc-m857.png "/>

Error warning you/home/xxxxxxx is not a directory, because the CP command requires multiple source files, the target must be a directory file, can be viewed through the man help

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/3A/wKiom1edjevTo8DhAAAc2d34GYc695.png "title=" 14.png "alt=" Wkiom1edjevto8dhaaac2d34gyc695.png "/>


5, the source is multiple files, the target is a file and exists

In the same way, according to man help, the target must be a directory file, so it is also an error

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/3A/wKioL1edjeyzO4YCAAAy-iwA064968.png "title=" 15.png "alt=" Wkiol1edjeyzo4ycaaay-iwa064968.png "/>


6, the source is multiple files, the target is a directory file and exists

Note the table of contents, this is very good understanding because the/home directory exists under the AA file, so the implementation of CP AA BB cc/home/operation will be reminded whether to overwrite, select Overwrite, and then to the/home directory can indeed see there is a AA bb cc file, this is easy to understand.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/3A/wKioL1edjezBECwgAABNMm9YZ6M760.png "title=" 16.png "alt=" Wkiol1edjezbecwgaabnmm9yz6m760.png "/>


7, the source is a directory file, the target is not exist (the copy directory file must use the-r option for recursion)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKiom1edjeyBtSivAAEARygFuwA107.png "title=" 17.png "alt=" Wkiom1edjeybtsivaaearygfuwa107.png "/>

The target does not exist, whether it is a file or a directory, will create the specified/aa/directory or/bb file, copy all the contents of the source directory to the target file or directory, through the LS view, it is indeed copied over.


8, the source is a directory file, the target already exists and for the file

If the source is a directory file, the target is the file that exists, the execution cp-r/etc/sysconfig//gg will error, meaning that the directory cannot overwrite the file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKiom1edjezTqTaQAABmMKQra4g269.png "title=" 18.png "alt=" Wkiom1edjeztqtaqaabmmkqra4g269.png "/>


9, the source is a directory file, the target already exists and is the directory

First/gg file does not exist, the first execution of Cp-r/etc/sysconfig//gg will be in accordance with the 7th case, the contents of the Sysconfig directory will be copied into the/gg file, the/gg is the directory, and then execute Cp-r/etc/ sysconfig//gg, this time will be under the target/GG to create a new Sysconfig directory, and the contents of the directory in the new sysconfig, then Ls/gg will find that there is a sysconfig directory, if you execute cp-r/etc /sysconfig//gg will appear whether to overwrite the reminder, if you do not need to remind the use of the command itself, rather than using our understanding of the-f option (the surface meaning is mandatory, actually the original file deleted, and then re-build one)

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/3A/wKioL1edje2ghj6nAAE881b0R60710.png "title=" 19.png "alt=" Wkiol1edje2ghj6naae881b0r60710.png "/>




This article is from the "Linux [email protected] Xueshuai" blog, be sure to keep this source http://xueshuai.blog.51cto.com/11578473/1832330

CP commands in Linux & old nine gates

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.