Linux Copy File command CP usage Commentary _linux Shell

Source: Internet
Author: User
Tags file copy


There are many commands under Linux, there is a command, I always use the problem, that is CP command. Each time you use this command, you are prompted to cp:omitting directiory error. Finally, Baidu to understand that the original CP command to copy the directory when the need to take command parameters. No wonder I used the CP command to complain. Here are some tips for using this command:



1. CP command syntax

CP [Options] <source file or directory> <target file or directory> or CP [options] Source1 Source2 ... director Y


The preceding syntax is a single file or directory copy, which is a copy of multiple files to the final directory. Options parameters include:



-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.



2. Use examples



I started using the command is CP file./direc This command works fine, but when you use CP Direc/DIRECT2 later, you report to cp:omitting directory.



Directory to directory replication using Cp-r Direc direc2, if all files under the directory including folders are copied to the DIREC2 directory, you can use the command cp-r direc/* to implement.



File to file copy (operation in same directory, equivalent to backup and renamed) Cp-i file1 file2 or CP file1 file2



At present, I still have such a low-level error, that I command or not familiar Ah, hey, later to learn more about Linux commands.



The above is a small series to introduce the Linux copy File command cp Use commentary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!


Related Article

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.