recorded, only for study, review use. ****************************
Learning environment: Ubuntu 16.04.2 LTS 64-bit
The CP command is used to copy one or more source files or directories to a specified destination file or directory. It can copy a single source file into a specific file with a specified file name or a directory that already exists. The CP command also supports copying multiple files at once, and when copying multiple files at a time, the target file parameter must be a directory that already exists, or an error will occur.
-A: The effect of this parameter is the same as specifying the "-dpr" parameter;-D: When the symbolic connection is copied, the destination file or directory is also established as a symbolic connection. and point to the original file or directory connected to the source fileor directory;-F: Forcibly copying a file or directory regardless of whether the destination file or directory already exists;-I: Ask the user before overwriting the existing file;-L: Establish a hard connection to the source file. instead of copying files;-p: Preserves the properties of the source file or directory;-r/R: Recursive processing, all files under the specified directory are processed together with subdirectories;-s: Create symbolic connections to source files, not copy files;- u: When this parameter is used, the file will only be copied when the source file change time is newer than the target file or the target file corresponding to the name does not exist;-S: When backing up the file, use the specified suffix "SUFFIX" instead of the default suffix of the file; B: The target file is backed up before overwriting the existing file target;-V: Details the actions performed by the command.
Example 1: Copy the files under one folder to a different folder.
Here, copy the two files in the catalogue/home/alpha/documents/otest "Plum rain Season1" and "Plum rain Season1" to/home/alpha/documents/dtest
The following error message appears when copying
Because the file is said to contain the lattice, so the copy can be in the space to meet with the escape symbol "\", or two English double brackets to enclose the entire file name containing the space, respectively, the following two ways to copy the file 1 and file 2.
The terminal did not error, and then go to dtest this directory to view, return to the present two files are copied to dtest this directory.
Example2: Folder and copy to a non-existent destination folder.
Otest This folder has a subfolder osub, copy it to Dtest/ddtest, but ddtest this folder does not exist.
These commands will be error, because the CP command only copy function, and do not have the ability to create a directory, we need to use the CP command-A or-R parameter.
Cp/home/alpha/documents/otest/osub/home/alpha/documents/dtest/ddtest
Execute the following command, create a new directory under the Dtest directory Ddtest ", and the source directory osub the following files and subdirectories and subdirectories will be copied into the ddtest inside.
CP -a/home/alpha/documents/otest//home/alpha/documents/dtest/ddtest
At this point, if we execute the above command again, then the Osub directory itself has been copied to ddtest under the Osub directory. Because when we once again this command, ddtest This directory already exists, the intention of this command is to copy the source directory to the target directory.
Compared to the above two, it is not difficult to find that the same CP command is executed again, osub this directory itself is copied to the first copy of the ddtest created when the directory.
Example 3: Copy the files below the directory to the specified directory.
Here, there is a directory named old that has two files
There's nothing under the directory named new.
Execute the following command to place the two files of the old directory in the new directory.
Note: It's old/* not old/.* or old*.
CP / home/alpha/documents/old/*/home/alpha/documents/new
Execute the following command, the file Old1 in the old directory will replace the same name file in the new directory without any hint.
CP /home/alpha/documents/old/old1/home/alpha/documents/new/old1
Cp-i
Executes the cp-i, prompting for overwrite before overwriting the file with the same name.
CP -i/home/alpha/documents/old/old1/home/alpha/documents/new/Old1cp'/ Home/alpha/documents/new/old1'? Y[email protected] CP -i/home/alpha/documents/old/old1/home/alpha/documents/new/Old1cp' /home/alpha/documents/new
Example 4: Copy and change the name
The following command copies the Old1 file to the new directory and renames it as "Imfromoldfolder".
CP /home/alpha/documents/old/old1/home/alpha/documents/new/imfromoldfolder
About the CP command more detailed two links
Http://www.jb51.net/article/101641.htm
Http://www.xuexila.com/diannao/xitong/linux/305357.html
Use of the copy CP command inside Linux