Common linux Command series-cp copy files and folders

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to learn how to copy files and folders using cp.
Command Name: cp(copy)Function Description: copy one file to another, or copy several files to another directory.
Syntax format:
   cp [options] source dest
cp [options] source... directory
Common parameters:
  -A tries its best to copy the file status, permissions, and other information as they are.
-R if the source contains the directory name, the files under the directory are also copied to the destination in sequence.
-F if the destination already has an archive with the same file name, delete it before copying.
Command instance:
1. copy the file aaa (already exists) and name it bbb:
   cp aaa bbb 2. Copy all C language programs to the Finished subdirectory:
   cp *.c Finished3. copy the file in the specified directory to the current directory and rename it. [root@rehat root]# cp ~/.bashrc bashrc_bak4. Force copy the file from the specified directory to the current directory, regardless of whether the current directory contains the file [root@rehat root]# cp -f ~/.bashrc bashrc5. Copy the specified directory to the current directory. [root@rehat root]# cp -r /root/test .
[root@rehat root]# cp -r /root/test/ .
The two have the same effect. When copying a directory, all the last-level directories in the source path will be copied, including the directory itself.
6. copy the files in the specified directory to the specified directory. [root@rehat root]# cp ~/.bashrc /bak/.bashrc7. Copy all the attributes of the source file during replication. If no parameter is specified, the properties of the target file and the source file may be inconsistent. [root@rehat root]# cp -a ~/.bashrc /bak/.bashrc8. If the two folders need to be synchronized, one file is changed, and the other file is changed, but ensure that the files of the two files are the latest. [root@rehat root]# cp -u /src/.bashrc /bak_src/bashrc9. Copy all files in the specified directory to the current directory. [root@rehat root]# cp -r /root/test/* .

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.