Usage of the cp command in Linux _ detailed introduction to the cp copy file (folder) command in linux

Source: Internet
Author: User
The cp command is used to copy files or directories. For example, if you specify more than two files or directories at the same time, and the final destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, but the last destination is not an existing Directory, an error message will appear.

Function: copy a file or directory.
Note: The cp command is used to copy files or directories. If you specify more than two files or directories at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, but the last destination is not an existing Directory, an error message will appear.
Parameters:
-A or -- archive: the effect of this parameter is the same as that of the "-dpR" parameter.
-B or -- backup deletes and overwrites the destination file. The backed up file or directory is also established as a symbolic link and points to the source file or directory link. If this parameter is not added, if a symbolic link is encountered during the copy process, the source file or directory will be copied directly.
-F or -- force forcibly copies a file or directory, regardless of whether the target file or directory already exists
-I or -- interactive ask the user before overwriting the file
-L or -- link creates a hard link to the source file instead of copying the file.
-P or -- preserve retains the attributes of the source file or directory, including the owner, group, permission, and time.
-P or -- parents retains the path of the source file or directory. This path can be an absolute or relative path, and the target directory must already exist in
-R recursive processing: processes the files in the specified directory along with subdirectories. If the source file or directory does not belong to a directory or symbolic link, it will be treated as a normal file.
-R or -- recursive processing, which processes the files and subdirectories under the specified directory together
-S or -- symbolic-link creates a symbolic link to the source file instead of copying the file.
-S <备份字尾字符串> Or -- suffix = <备份字尾字符串> After the target file is backed up with the "-B" parameter, a backup string is added at the end of the backup file. The default backup suffix is a symbol "~ "
-U or -- update: After this parameter is used, the file will be copied only when the source file's Modification Time (Modification Time) is newer than the target file, or the target file with the corresponding names does not exist.
-V or -- verbose displays the execution process
-V <备份方式> Or -- version-control = <备份方式> Specifies the naming method of the backup file name when the backup file is being backed up:
1. numbered or t, the backup number will be used, and ~ will be added at the end of the word ~ 1 ~ String, whose numbers are incremented in turn
2. simple or never will use simple backup. The default backup character string is ~, You can also use-S to specify
3. existing or nil will use the current method. The program will first check whether there is a backup number. If yes, the backup number will be used. If not, a simple backup will be used.
-X or -- one-file-system: the file system in which the file or directory is copied must be the same as the file system in which the cp command is executed; otherwise, the file system will not be copied, files in other partitions are not processed.
-- Help displays online help
-- Sparse = <使用时机> Set the time to save the xishu File
-- Display version

Example:
. Copy the file. The file is copied only when the source file is modified later than the target file.
Cp-u-v file1 file2

. Copy file file1 to file file2
Cp file1 file2

. Copy file file1 to file file2.
Cp-I file1 file2

. Copy the file file1 to file2. Because the target file already exists, use the forced copy mode.
Cp-f file1 file2

. Copy the directory dir1 to the directory dir2
Cp-R file1 file2

. Copy the file file1, file2, file3, and directory dir1 to dir2.
Cp-R file1 file2 file3 dir1 dir2

. File attributes are retained during replication.
Cp-p a.txt tmp/

. The directory structure of the file is retained during replication.
Cp-P/var/tmp/a.txt./temp/

. Backup files generated during replication
Cp-B a.txt tmp/

. The backup file is generated during replication ~ 1 ~ Format
Cp-B-V t a.txt/tmp
 
. Specifies the tail mark of the backup file
Cp-B-S _ bak a.txt/tmp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.