One Linux command per day (7): CP

Source: Internet
Author: User

CP Command
The function of this command is to copy the given file or directory to another file or directory, which is as powerful as the copy command under MSDOS.
Grammar:CP [option] source file or directory destination file or directory

Note: This command copies the specified source files to the destination file or copies multiple source files to the destination directory.

The options for this command have the following meanings:

-A This option is typically used when copying a directory. It retains links, file attributes, and recursively copies the directory, which is equal to the combination of the DPR option.

-D Copy to keep the link.

-F Delete a target file that already exists without prompting.

The-I and F options, in contrast, will prompt the user for confirmation before overwriting the target file. Answer y when the target file will be overwritten, is an interactive copy.

-P At this point the CP will also copy its modification time and access rights to the new file, in addition to copying the contents of the source file.

-R If the source file is a directory file, the CP will recursively replicate all subdirectories and files in that directory. The destination file must be a directory name at this time.

-L does not make a copy, just a link file.

It should be explained that in order to prevent the user inadvertently using the CP command to destroy another file, such as the user specified target file name already exists, the CP command after copying the file, the file will be overwritten by the Xinyuan file, it is recommended that users use the CP command to copy files, it is best to use the I option.

Example:
cp-i file1 file2Copy the document FILE1 into File2. –i for prompt confirmation.

CP file1 Dir1Copy the document FILE1 to directory Dir1, and the file name is still file1.

Cp/tmp/file1.Copy the document FILE1 under directory/TMP to the current directory, and the file name is still file1.

cp/tmp/file1 file2File1 the document under the directory/TMP under the current directory, with the file name File2

cp-r dir1 Dir2(recursive copy) copies the entire directory. If the directory Dir2 does not exist, copy the directory Dir1, and all of its documents and subdirectories, to the directory Dir2, and the new directory name is Dir1. If the directory Dir2 does not exist, the dir1, and all of its documents and subdirectories, are copied to the directory Dir2.


======================================================================

The CP (copy) command copies a file, multiple files, or directories to another location.
The option-R allows recursive copying of directories (in general, the-R or-R in the command often has the meaning of recursion).
If the last parameter of the CP command is a directory, the file mentioned will be copied to that directory.
Note: By default, the CP command will "overwrite" files that already exist.

Take a look at the following example:

CP afile Afile.bak--Copy the file Afile to the new file Afile.bak.

CP afile/home/bible/--Copy the file Afile from the current directory to the/home/bible/directory.

CP */tmp--Copy all the hidden files under the current directory to the/tmp/directory.

cp-a Docs Docs.bak--Recursion first copy the Docs directory in the current directory to the new directory Docs.bak, keep the file attributes, and copy all the files, including hidden files that begin with a period. For convenience, the-a option implies the-r option.

cp-i--If you want to copy the file to a directory that already exists for the same file, the old file will be overwritten by default. The-I option allows the command to interact, in other words, to ask the user before overwriting.

cp-v--With the-V (verbose) option, the CP command tells the user what is being done. Many Linux commands have a-v option with the same meaning.

One Linux command per day (7): CP

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.