Linux CP command Copy file __linux

Source: Internet
Author: User

The

Linux CP Command Copy command is very useful, and the CP command can copy files (directories) under the specified path to another file or directory, equivalent to DOS copy and Xcopy commands. The CP command syntax is as follows:

CP [Options] <source file or directory> <target file or directory>
Or
CP [Options] source1 source2 source3 ... directory
The first command above is a copy of a single file or directory, and the next one is copied to the final directory for multiple files.
The options option includes:
-a preserves the link and file attributes, recursively copies the directory, equivalent to the following D, P, r three option combinations.
-D Keep links when copying.
-F Deletes the destination file that already exists without prompting.
-I will give a confirmation prompt before overwriting the target file, which is an interactive copy.
-P Copies the contents of the source file and also copies its modification time and access rights to the new file.
-R If the source file is a directory file, the CP will recursively replicate all subdirectories and files in the directory. Of course, the destination file must be a directory name.
-L do not copy, just link file.
-s copy into the symbolic link file (symbolic link), the "shortcut" file;
-U if destination is newer than source old destination.
Example of CP command usage:
1, copy the document FILE1 into File2, after the name is changed file2
Cp-i file1 file2
Or
CP file1 File2
2, copy the document FILE1 to the Dir1 directory, after the name has not been copied file1
Cp-i file1 Dir1
Or
CP File1 Dir1
3, the directory Dir1 copied to the Dir2 directory, the replication results directory was renamed DIR2
Cp-r Dir1 Dir2
4, the directory Dir1 all files including folders, are copied to the Dir2 directory
Cp-r dir1/*.* Dir2
Common errors:
1. Prompt cp:omitting Directory Error
When replicating a directory, use the-r option to copy recursively, as follows:
Cp-r Dir1 Dir2

Instance:

First, copy a directory under the/opt/a/to the/opt/b/directory

Cp-r/opt/a//opt/b/A. Record under/opt/a/to the/opt/b/directory


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.