How to copy the entire directory command under CentOS? How to copy the directory command under CentOS

Time:2020-2-13

The function of this command is to copy the given file or directory to another file or directory, just like the copy command under DOS, it is very powerful.

grammar: CP [options] source file or directory target file or directory

Explain: this command copies the specified source file to the target file or multiple source files to the target directory.

Meaning of each option

-A this option is usually used when copying directories. It preserves links, file attributes, and recursively copies directories as a combination of DPR options.

-D keep the link when copying.

-F delete the existing target file without prompting.

-The I and f options are the opposite. You will be prompted for confirmation before overwriting the target file. When you answer y, the target file will be overwritten. It is an interactive copy.

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

-R if the given source file is a directory file, then CP will recursively copy all subdirectories and files under the directory. The target file must be a directory name at this time.

-L do not make copies, just link files.

It should be noted that: to prevent the user from accidentally destroying another file with the CP command, for example, the target file name specified by the user is an existing file name. After copying the file with the CP command, the file will be overwritten by the new copy of the source file. Therefore, it is recommended that the user use the I option when copying the file with the CP command.

$ cp – i exam1.c /usr/wang/shiyan1.c

This command copies the file exam1. C to the directory / usr / Wang and changes its name to shiyan1. C

If you do not want to rename, you can use the following command:

$ cp exam1.c /usr/ wang/

Copy all the files and subdirectories in the / usr / Xu directory to the directory / usr / Liu. The command is as follows:

$ cp – r /usr/xu/ /usr/liu/