Linux learns a command's CP command every day

Source: Internet
Author: User

recently learning to copy files in linux command CP, the learning record is as follows
CP [option] Source (source file) destination (destination file)CP [Options] Source1Source2 Source3Source4source5 ... directory
CP command can copy files or folders, can be followed by multiple source files, when there are multiple source files, the last parameter is the destination directory to be stored, if the destination directory does not exist, not the destination directory will be an error. As shown in the following:
   
 
  1. [[email protected] ~]# ll
  2. 总用量 8
  3. -rw-------. 1 root root 1585 4月 29 09:11 anaconda-ks.cfg
  4. - RW - r -- r --. 1 root root 1633 4 month Span class= "lit" >29 17 : 03 initial - setup Span class= "pun" >- ks cfg
  5. [[email protected] ~]# cp /etc/asound.conf /etc/bashrc anaconda-ks.cfg
  6. cp: 目标"anaconda-ks.cfg" 不是目录
  7. [[email protected] ~]# cp /etc/asound.conf /etc/bashrc tmp
  8. cp: 目标"tmp" 不是目录

Here's a look at the option parameter:-A: Equivalent to-dr-d: If the file is a linked file, the linked file will be copied instead of the file itself-F: To force replication-L: The replication of the link, not the copy-P of the document itself, along with the properties of the document (permission, user, time), Instead of using the preset properties of the copy-r: Copy recursively, use the option-s: Copy as Symbolic link-u: Compare the source file with the destination file and copy it if there is an update
Here's a look at some examples:
Example one: Copy Test to Test_root
  
 
  1. [[email protected] dream]# ll
  2. 总用量 0
  3. - RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test
  4. -rw-rw-r--. 1 dream dream 0 5月 11 09:58 test.log
  5. [[email protected] dream]# cp test test_root
  6. [[email protected] dream]# ll
  7. 总用量 0
  8. -rw-rw-r--. 1 dream dream 0 5月 11 09:58 test
  9. - RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test log
  10. -rw-r--r--. 1 root root 0 5月 11 09:58 test_root

Example two: Copy the ETC directory to the./tmp directory
 
   
  
  1. [[email protected] dream]# cp -r /etc/ ./tmp/

Example three:put/etc/Rc.local the link file to the current directory and keep the link without copying the file itself
  
 
  1. [[email protected] dream]# cp /etc/rc.local ./
  2. [[email protected] dream]# ll
  3. 总用量 4
  4. - RW - r -- r --. 1 root root 473 5 month Span class= "lit" >11 10 : 11 RC local
  5. [[email protected] dream]# cp -d /etc/rc.local ./
  6. [[email protected] dream]# ll
  7. 总用量 0
  8. lrwxrwxrwx. 1 root root 13 5月 11 10:13 rc.local -> rc.d/rc.local

After reading the above examples, we can see that the properties of the destination file will change with the execution of the current command when the file is copied, and if you need to preserve the original property, you can use the-P option parameter
  
 
  1. [[email protected] dream]# ll
  2. 总用量 0
  3. -rw-rw-r--. 1 dream dream 0 5月 11 09:58 test
  4. [[email protected] dream]# cp -p test ./test.tmp
  5. [[email protected] dream]# ll
  6. 总用量 0
  7. - RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test
  8. -rw-rw-r--. 1 dream dream 0 5月 11 09:58 test.tmp

Summary: The CP command copies the file when it is associated with the command's executor; When you want to copy multiple files, the last parameter must be the directory

Linux learns a command's CP command every day

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.