Common Linux commands (7)-cp

Source: Internet
Author: User

Common Linux commands (7)-cp

The cp command is used to copy files or directories. It is one of the most common commands in Linux. In general, shell sets an alias. When copying a file under the command line, if the target file already exists, it will ask whether to overwrite the file, whether or not you use the-I parameter. However, if you run cp in a shell script, if you do not have the-I parameter, you will not be asked whether to overwrite it. This indicates that the command line and shell script are executed differently.

1.Command Format:

Cp [Option]... source... target directory

2.Command function:

Copy the source file to the target file, or copy multiple source files to the target directory.

3. command parameters:

-A, -- archive creates a backup for each existing target file
-B is similar to -- backup but does not accept parameters
-D -- no-dereference -- preserve = links
-F, -- force: if the target file cannot be opened, remove it and try again (this option is not required when the-n option exists)
-I, -- interactive overwrite the previous query (invalidate the previous-n option)
-H follows the command line symbolic link in the source file
-L, -- link file without copying
-L, -- dereference always follows the Symbolic Link
-N, -- no-clobber do not overwrite existing files (invalidate the previous-I option)
-P, -- no-dereference does not follow the symbolic link in the source file
-P -- preserve = mode, ownership, timestamp
-R,-r, -- recursive: copy the Directory and all projects in the directory

4. Command instance:

Instance 1:Copy a single file to the target directory. The file does not exist in the target folder.

Command: cp log. log test5

If the target file exists, you will be asked if it is overwritten.

Example 2:Copy the entire directory

Command: cp-a test3 test5

Note: The results of the existence of the target directory are different. When the target directory exists, the entire source directory is copied to the target directory.

Example 3:Create link file

Command: cp-s log. log log_link.log

[root@localhost test]# cp -s log.log log_link.log[root@localhost test]# lllrwxrwxrwx 1 root root    7 10-28 15:18 log_link.log -> log.log

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.