Linux CP Command detailed

Source: Internet
Author: User
Tags file copy

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" J_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" j_0003.gif "/>

Copy Files and Directory

File copy and move for most computer enthusiasts is familiar with the window under the right mouse button copy paste, rename and so on, looking at is so simple, but a lot of steps, but in the Linux file copy and move is just a command can be achieved , Let's take a look at the copy command in the file.

Name:

CP (copy files and directory) copy file and directory

Command format:

CP [Options] ... SOURCE... DESC

"..." means that the source file can have multiple so we can get the conclusion from the above:

    1. CP can only copy one file into another file

    2. CP can copy multiple files to a directory

3. If there are many files behind the CP, then the last one must be a directory

Let's take a look at the actual usage of the CP in the code:

[Email protected] ~]$ cp/etc/man_db.conf/tmp/test[[email protected] ~]$ ls/tmp/anaconda.log storage.loghsperfdata _root Systemd-private-3e1wlmifcfg.log systemd-private-cxuwsvks-script-5gepg3 Systemd-private-stjruypackaging.lo G Testprogram.log vmware-rootssh-x1rdjkugnlhn Yum.log[[email protected] ~]$


This command is to copy the man_db.conf to the/tmp/and rename the file to test.

If the target file exists in the target directory, the contents of the source file will overwrite the target file

[Email protected] tmp]$ cp/etc/man_db.conf/tmp/test[[email protected] tmp]$ cp/etc/locale.conf/tmp/testcp: Whether or not to overwrite the/tmp /test "?


Is that clear? Notice here the CP interaction is because in alias defines an alias cp= ' cp-i ' reason, I is a CP option to achieve the role of human-computer interaction, where the coverage is actually equivalent to the original test file deleted, and then copy the source files to/tmp/ and change the name to test, we have to understand

But what if test is an eye under/tmp/?

[[email protected] tmp]$ cp/etc/man_db.conf/tmp/test[[email protected] tmp]$ Ls/tmp/testman_db.conf[[email protected] tmp]$


This makes sense, copy the source file to the test directory, the name of the source file does not change

Let's look at a piece of code like this

[Email protected] tmp]$ cp/etc/init.d//TMP/CP: Skip Directory "/etc/init.d/" [[email protected] tmp]$


What this means, the reason is very simple, the CP default mechanism is to copy files, do not copy the directory, but we want to copy directory changes how to implement it?

-r:[recursive options] Copy all files in a directory and its directory

[[email protected] tmp]$ cp-r/etc/init.d//tmp/home[[email protected] tmp]$ ls/tmp/homefunctions netconsole Network Readme[[email protected] tmp]$


So, do you see it clearly? -R will be a directory and all the files in the directory recursively copied out to the target directory, we look carefully,/TMP is not home directory, such execution will directly create a home directory and the home directory contains the contents of the source directory, do you understand?

If home is a file, let's see what happens.

[Email protected] tmp]$ cp-r/etc/init.d//TMP/1CP: Cannot overwrite non-directory "/etc/init.d/" with Directory "/TMP/1" [[email protected] tmp]$


You will be prompted CP: Can not be in the directory "/etc/init.d/" to overwrite the non-directory "/TMP/1", but in some versions of the system is executable, the result is to overwrite the contents of the file, and create an error link without the source file, okay, here's a note.

Let's take a look at some of the other options for CP

-F: Indicates forced replication

If the target file exists, not human-computer interaction, directly overwrite the file content, is not very overbearing?

[Email protected] tmp]$ cp-f/etc/man_db.conf/tmp/1[[email protected] tmp]$


-I: Interpersonal interaction, we've talked about it before.

-P: Reserved file owner, group, timestamp

[Email protected] tmp]$ cp-p/storage.log/storage.log1[[email protected] tmp]$ ll-rw-r--r--. 1 root root 0 March 9 23:36 storage.log-rw-r--r--. 1 Jason Jason 0 March 9 23:36 storage.log1


-L: Copy the link, actually copy the link to the file (the default is-L)

[Email protected] etc]$ lllrwxrwxrwx. 1 root root 13 March 07:19 rc.local-Rc.d/rc.local[[email protected] etc]$ cp-l/etc/rc.local/tmp/[[email PR Otected] etc]$ ll/tmp-rw-r--r--. 1 Jason Jason 473 March 16:59 rc.local


What do you mean, see what it means? Copied over to show a file, the content of the file is rc.d/rc.local content, not the link

-P: Keep the link itself

[Email protected] etc]$ cp-p/etc/rc.local/tmp/rc12.local[[email protected] etc]ll/tmplrwxrwxrwx. 1 Jason Jason 13 March 17:04 rc12.local-rc.d/rc.local

The original is the link, copied over or link

-d: Copy the link itself as with-p

-R: As with-R, recursion

-A:same as-dr, guess what that means 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" j_ 0006.gif "/>","archive" is not to change all the properties of the file, backup storage

Okay, here's the demo, CP. I think you will be memorized in heart, in the back to consolidate the consolidation of it 650) this.width=650, "src=" Http://img.baidu.com/hi/jx2/j_0063.gif "alt=" J_0063.gif "/>

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/ Jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" j_ 0006.gif "/>650) this.width=650;" src= "Http://img.baidu.com/hi/jx2/j_0006.gif" alt= "J_0006.gif"/>650 " this.width=650, "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" http ://img.baidu.com/hi/jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/jx2/j _0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" j_0006.gif "/>650) this.width=650;" src= "Http://img.baidu.com/hi/jx2/j_0006.gif" alt= "J_0006.gif"/>650 "this.width=650;" Src= "Http://img.baidu.com/hi/jx2/j_0006.gif" alt= "J_0006.gif"/>650) this.width=650; " Src= "Http://img.baidu.com/hi/jx2/j_0006.gif" alt= "J_0006.gif"/>650) this.width=650; src= http://img.baidu.com /hi/jx2/j_0006.gif "alt=" J_0006.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0006.gif "alt=" J _0006.gif "/>

This article is from the "Jasonforcto" blog, make sure to keep this source http://xuelong.blog.51cto.com/10573089/1749664

Linux CP Command detailed

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.