As a matter of fact, the CP command is quite common for everyone. I don't have to be here. Until I found that CP is not simple enough for everyone to ignore.
Here are two examples. You can pay attention to the following in the future study:
1) The permission to copy files is not always the same for CP files.
[Root @ localhost test] # Touch
[Root @ localhost test] # Vim
[Root @ localhost test] # ls
A
[Root @ localhost test] # ls-l
Total 8
-RW-r -- 1 Root 24 04-29 00:04
[Root @ localhost test] # CP A B
[Root @ localhost test] # ls
A B
[Root @ localhost test] # ls-l
Total 16
-RW-r -- 1 Root 24 04-29 00:04
-RW-r -- 1 Root 24 04-29 00:04 B
[Root @ localhost test] # chmod 755
[Root @ localhost test] # ls-l
Total 16
-Rwxr-XR-x 1 Root 24 04-29 00:04
-RW-r -- 1 Root 24 04-29 00:04 B
[Root @ localhost test] # CP A B
CP: overwrite "B "? Y
[Root @ localhost test] # ls-l
Total 16
-Rwxr-XR-x 1 Root 24 04-29 00:04
-RW-r -- 1 Root 24 04-29 00:05 B
[Root @ localhost test] #
As shown in the preceding example, when file a is created, the permission of file a is 644. Copy a file B and check that the permission for file B is 644. The permission of the CP File follows.
Later, we changed the permission of file a to 755, and copied file a to file B again. Now we can view the permission of file B again, and the permission of file B is still 644, this proves that the permission of the file in CP is not followed.
If the target file does not exist, the permission can be obtained from the source file to the target file. If the target file already exists, the permission of the source file will not be imposed on the target file.
2) CP is not always successful.
If you want to CP a directory, you must use CP-R to copy it. the following example:
[Root @ localhost test] # ls
[Root @ localhost test] # mkdir
[Root @ localhost test] # mkdir B
[Root @ localhost test] # l
Total 32
Drwxr-XR-x 4 Root 4096 04-29.
Drwxr-XR-x 4 Root 4096 04-29 ..
Drwxr-XR-x 2 root Root 4096 04-29
Drwxr-XR-x 2 root Root 4096 04-29 B
[Root @ localhost test] # CP A B
CP: Skip directory ""
[Root @ localhost test] # L B
Total 16
Drwxr-XR-x 2 root Root 4096 04-29.
Drwxr-XR-x 4 Root 4096 04-29 ..
[Root @ localhost test] # cp-R A B
[Root @ localhost test] # L B
Total 24
Drwxr-XR-x 3 Root 4096 04-29.
Drwxr-XR-x 4 Root 4096 04-29 ..
Drwxr-XR-x 2 root Root 4096 04-29
[Root @ localhost test] #
Both A and B are directories. The first time you use the CP command to copy files, the copy failed. Prompt CP: Skip directory ""
The second copy, with the-r option added, CP is successful.