0. CP command (copy file or directory)
1. # CP [-adfilprsu] source file (source) destination (destination)
2. # CP [Options] Source1 source2 source3 .... directory
Parameters:
-A (archive): equivalent to the meaning of-pdr; do not change all properties of the source for archival replication, often used for backup; =--backup
-D (no-dereference) : If the source file is the attribute of the linked file, the link file property is copied rather than the file itself; that is , if the source is a link, the copy links
- F (Force): In the sense of coercion, if there is any duplication or other doubt, the user will not be asked , but forced to copy;
-I (Interactive): If the destination file (destination) already exists, the overwrite will first ask whether the action is true!
-L (link files instead of copying) : The link file for the hard link is established rather than the copy itself; that is, if the source is a link, the files that the links point to are copied;
-P (no-dereference) : Keep Link: If the source is a link, copy the link
- p (not changing the source's owner group): Copy the past together with the attributes of the archive, rather than using the default attributes;
What is a preset attribute: Who was originally copied, and who was the owner of the file;
-R (Recursive): Recursive continuous replication, used for directory replication behavior;
-S (symbolic): Copy becomes the symbolic link file (symbolic link), i.e. "shortcut" files;
-U (UPDATE): Update destination If destination is older than source, or destination file is missing
1. Questions
Question 1: can copy a file into another file, a file copied into multiple files, multiple files copied into a file. that is src:dest = 1:1,1:n,n:1,n:n
inductive 1: There is only one target destination, which can be a file or a directory. So there are only two cases of src:dest=1:1 and N:1 , But in the case of multiple sources (i.e., src:dest=n:1 ), the target (Dest) can only be a directory , otherwise error.
Question 2: What are symbolic links?
A: The equivalent of a shortcut, itself does not exist, but a path to another file.
If the source is a link, the copy is not the link but the file that the link points to
question 3: CP command, cannot copy directory by default, then how to implement copy directory
Answer: # cp-r (recursive recursion):
Recursive continuous replication for the replication behavior of the directory;
# CP- R /etc/init.d/tmp/passwd (directory to file?) ) can the command be executed?
instruction Interpretation: src for the directory, dest for the file; src:dest=1:1
In the absence of the R parameter, execution is not allowed.
The instruction executes
2. Example
A source
Example 1: # cp/etc/passwd/tmp, What do you mean?
A: src file, dest for the directory;
Instruction Interpretation:
The file passwd under/etc path is copied to the target directory/TMP and the copied file name is still passwd.
Example 2: # cp/etc/passwd/tmp/test, what do you mean?
A: SRC is a file, dest is a directory or file;
Instruction Interpretation:
1. When dest (test) is a file:
Copy the file passwd to the directory/tmp:
1.1 If test does not exist, the copy file is saved in the/tmp directory with test as file name;
1.2 if test already exists, ask the user whether to overwrite the original test file with the newly copied file;
2. When dest (test) is a directory:
The file is passwd, copied to the directory/TMP, and the copied file name is still passwd.
Multiple sources
Example 3 : # cp/etc/passwd/etc/issue/etc/inittab/tmp/abc, what do you mean?
A: SRC:DEST=N:1;SRC is a file, Dest is a file or directory
Instruction Interpretation:
1. When Dest (ABC) is a file:
The question is, can multiple files be stored in a single file?
The answer is no, when the user tries to store multiple files in a file, the system will indicate that the target ABC is not a directory.
2. When Dest (ABC) is a directory:
The source file (Passwd,issue,inittab) is copied to the target directory/TMP/ABC, and the file is saved with the original file name.
About the CP command in Linux