The CP command is used to copy files or directories and is one of the most commonly used commands in a Linux system. In general, the shell sets an alias, and when the file is copied at the command line, if the destination file already exists, it asks whether to overwrite it, regardless of whether you use the-i parameter. However, if you execute the CP in a shell script, you do not ask for overrides if you do not have the-i parameter. This means that the command line and shell scripts perform somewhat differently.
1. Command format:
Usage:
CP [OPTION] [-t] source purpose
OR: CP [options] Source directory
OR: CP [option]-T directory source
2. Command function:
Copy the source file to the destination file, or copy multiple source files to the destination directory.
3. Command parameters:
-A--archive equals-dr--perserve=all--backup[=control Create a backup for each existing target file
-B--copy-contents in recursive processing is to copy special file contents
-D equals--no-dereference--preserve=links
-F--force Remove the target file if it cannot be opened and try again (you do not need to select this when the-N option exists)
-I--interactive ask before overwriting (invalidates the previous-n option)
-H follow the command-line symbolic link in the source file
-l--link link file without copying
-L--dereference always follow the symbolic link
-N--no-clobber do not overwrite existing files (invalidates the previous-i option)
-P--no-dereference do not follow symbolic links in source files
-P equals--preserve= mode, ownership, timestamp
The--preserve[= property list retains the specified property (default: Mode, ownership, timestamp) if additional properties may be maintained: environment, links, xattr, etc.
-r-r--recursive Copy all items in directory and directory
4. Command instance:
Instance one: Copy a single file to the destination directory, the file does not exist in the destination file
Command:
CP Today.log back to copy today's log Today.log to the Go folder, when there is no with-a parameter, the time of the two files is not the same. When the-a parameter is taken, the time of the two files is consistent.
If you already have a copy of the Today.log file in the back folder, because I have a backup every day. At this point, it will prompt you to overwrite the existing file.
If you use the-f parameter and still prompt for coverage, check to see if your CP is a cp-i alias.
Example three: Copying the entire directory
Command:
Cp-a back Back1 copy all back to Back1
This is to distinguish between the existence of a back1 and the absence of a target directory, where the entire source directory is copied to the target directory.
Example four: Copy the Today.log to create a linked file Log_link.log
Command:
Cp-s Today.log Log_link.log
Log_link.log is caused by the-s parameter, which is created by a shortcut, so you will see at the far right of the file, which will show where the file is linked to.
Every day a Linux command (--CP) command