📄 cp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>cp</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_187"> </a>NAME</h4><blockquote>cp - copy files</blockquote><h4><a name = "tag_001_014_188"> </a>SYNOPSIS</h4><blockquote><pre><code>cp <b>[</b>-fip<b>]</b><i> source_file target_file</i>cp <b>[</b>-fip<b>]</b><i> source_file</i> ... <i>target</i>cp -R <b>[</b>-fip<b>]</b><i> source_file</i> ... <i>target</i>cp -r <b>[</b>-fip<b>]</b><i> source_file</i> ... <i>target</i></code></pre></blockquote><h4><a name = "tag_001_014_189"> </a>DESCRIPTION</h4><blockquote>The first synopsis form is denoted by two operands, neither of whichare existing files of type directory.The<i>cp</i>utility will copy the contents of<i>source_file</i>to the destination path named by<i>target_file.</i><p>The second synopsis form is denoted by two or more operands where the<b>-R</b>or<b>-r</b>options are not specified and the first synopsis form is not applicable.It is an error if any<i>source_file</i>is a file of type directory, if<i>target</i>does not exist or if<i>target</i>is a file of a type defined by the <b>XSH</b> specification,but is not a file of type directory.The<i>cp</i>utility will copy the contents of each<i>source_file</i>to the destination path named by the concatenation of<i>target,</i>a slash character and the last component of<i>source_file.</i><p>The third and fourth synopsis forms are denoted by two or moreoperands where the<b>-R</b>or<b>-r</b>options are specified.The<i>cp</i>utilitywill copy each file in the file hierarchy rooted in each<i>source_file</i>to a destination path named as follows.<p>If<i>target</i>exists and is a file of type directory, the name of thecorresponding destination path for each file in the file hierarchywill be the concatenation of<i>target,</i>a slash character and thepathname of the file relative to the directory containing<i>source_file.</i><p>If<i>target</i>does not exist and two operands are specified, the name ofthe corresponding destination path for<i>source_file</i>will be<i>target;</i>the name of the corresponding destination path for all other files inthe file hierarchy will be the concatenation of<i>target,</i>a slash character and the pathname of the file relative to<i>source_file.</i><p>It is an error if<i>target</i>does not exist and more than twooperands are specified, or if<i>target</i>exists and is a file of a type defined by the <b>XSH</b> specification,but is not a file of type directory.<p>In the following description,<i>source_file</i>refers to the file thatis being copied, whether specified as an operand or a file in a filehierarchy rooted in a<i>source_file</i>operand.The term<i>dest_file</i>refers to the file named by the destination path.<p>For each<i>source_file,</i>the following steps will be taken:<ol><p><li>If<i>source_file</i>references the same file as<i>dest_file,</i><i>cp</i>may write a diagnostic message to standard error;it will do nothing more with<i>source_file</i>and will go on to any remaining files.<p><li>If<i>source_file</i>is of type directory, the following steps will be taken:<ol type = a><p><li>If neither the<b>-R</b>or<b>-r</b>options were specified,<i>cp</i>will write a diagnostic message to standard error, do nothing more with<i>source_file</i>and go on to any remaining files.<p><li>If<i>source_file</i>was not specified as an operand and<i>source_file</i>is dot or dot-dot,<i>cp</i>will do nothing more with<i>source_file</i>and go on to any remaining files.<p><li>If<i>dest_file</i>exists and it is a file type not specified by the <b>XSH</b> specification,the behaviour is implementation-dependent.<p><li>If<i>dest_file</i>exists and it is not of type directory,<i>cp</i>will write a diagnostic message to standard error,do nothing more with<i>source_file</i>or any files below<i>source_file</i>in the file hierarchy, and go on to any remaining files.<p><li>If the directory<i>dest_file</i>does not exist, it will be createdwith file permission bits set to the same value as those of<i>source_file</i>,modified by the file creation mask of the user if the<b>-p</b>option was notspecified, and then bitwise inclusively ORed with S_IRWXU.If<i>dest_file</i>cannot be created,<i>cp</i>will write a diagnostic message to standard error,do nothing more with<i>source_file,</i>and go on to any remaining files.It is unspecified if<i>cp</i>will attempt to copy files in the file hierarchy rooted in<i>source_file.</i><p><li>The files in the directory<i>source_file</i>will be copied to the directory<i>dest_file</i>,taking the four steps [1-4] listed here with the files as<i>source_file</i>s.<p><li>If<i>dest_file</i>was created, its file permission bits will be changed(if necessary) to be the same as those of<i>source_file,</i>modified by the file creation mask of the user if the<b>-p</b>option was not specified.<p><li>The<i>cp</i>utility will do nothing more with<i>source_file</i>and go on to any remaining files.<p></ol><p><li>If<i>source_file</i>is of type regular file,the following steps will be taken:<ol type = a><p><li>If<i>dest_file</i>exists, the following steps are taken:<ol type = i><p><li>If the<b>-i</b>option is in effect, the<i>cp</i>utility will writea prompt to the standard error and read a line from the standard input.If the response is not affirmative,<i>cp</i>will do nothing more with<i>source_file</i>and go on to any remaining files.<p><li>A file descriptor for<i>dest_file</i>will be obtained byperforming actions equivalent to the <b>XSH</b> specification<i><a href="../xsh/open.html">open()</a></i>function called using<i>dest_file</i>as the<i>path</i>argument, and the bitwise inclusive OR of O_WRONLY and O_TRUNC as the<i>oflag</i>argument.<p><li>If the attempt to obtain a file descriptor fails and the<b>-f</b>option is in effect,<i>cp</i>will attempt to remove the file byperforming actions equivalent to the <b>XSH</b> specification<i><a href="../xsh/unlink.html">unlink()</a></i>function called using<i>dest_file</i>as the<i>path</i>argument.If this attempt succeeds,<i>cp</i>will continue with step 3b.<p></ol><p><li>If<i>dest_file</i>does not exist, a file descriptor will beobtained by performing actions equivalent to the <b>XSH</b> specification<i><a href="../xsh/open.html">open()</a></i>function called using<i>dest_file</i>as the<i>path</i>argument, and the bitwise inclusive OR of O_WRONLY andO_CREAT as the<i>oflag</i>argument.The file permission bits of<i>source_file</i>will be the<i>mode</i>argument.<p><li>If the attempt to obtain a file descriptor fails,<i>cp</i>will write a diagnostic message to standard error,do nothing more with<i>source_file,</i>and go on to any remaining files.<p><li>The contents of<i>source_file</i>will be written to the file descriptor.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -