Common Linux commands (7)-cp
The cp command is used to copy files or directories. It is one of the most common commands in Linux. In general, shell sets an alias. When copying a file under the command line, if the target file already exists, it will ask whether to overwrite the file, whether or not you use the-I parameter. However, if you run cp in a shell script, if you do not have the-I parameter, you will not be asked whether to overwrite it. This indicates that the command line and shell script are executed differently.
1.Command Format:
Cp [Option]... source... target directory
2.Command function:
Copy the source file to the target file, or copy multiple source files to the target directory.
3. command parameters:
-A, -- archive creates a backup for each existing target file
-B is similar to -- backup but does not accept parameters
-D -- no-dereference -- preserve = links
-F, -- force: if the target file cannot be opened, remove it and try again (this option is not required when the-n option exists)
-I, -- interactive overwrite the previous query (invalidate the previous-n option)
-H follows the command line symbolic link in the source file
-L, -- link file without copying
-L, -- dereference always follows the Symbolic Link
-N, -- no-clobber do not overwrite existing files (invalidate the previous-I option)
-P, -- no-dereference does not follow the symbolic link in the source file
-P -- preserve = mode, ownership, timestamp
-R,-r, -- recursive: copy the Directory and all projects in the directory
4. Command instance:
Instance 1:Copy a single file to the target directory. The file does not exist in the target folder.
Command: cp log. log test5
If the target file exists, you will be asked if it is overwritten.
Example 2:Copy the entire directory
Command: cp-a test3 test5
Note: The results of the existence of the target directory are different. When the target directory exists, the entire source directory is copied to the target directory.
Example 3:Create link file
Command: cp-s log. log log_link.log
[root@localhost test]# cp -s log.log log_link.log[root@localhost test]# lllrwxrwxrwx 1 root root 7 10-28 15:18 log_link.log -> log.log