⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cp.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<p>The user ID and group ID. If this duplication fails for any reason, it is unspecified whether <i>cp</i> writes a diagnosticmessage to standard error.</p></li><li><p>The file permission bits and the S_ISUID and S_ISGID bits. Other, implementation-defined, bits may be duplicated as well. Ifthis duplication fails for any reason, <i>cp</i> shall write a diagnostic message to standard error.</p></li></ol><p>If the user ID or the group ID cannot be duplicated, the file permission bits S_ISUID and S_ISGID shall be cleared. If thesebits are present in the source file but are not duplicated in the destination file, it is unspecified whether <i>cp</i> writes adiagnostic message to standard error.</p><p>The order in which the preceding characteristics are duplicated is unspecified. The <i>dest_file</i> shall not be deleted ifthese characteristics cannot be preserved.</p></dd><dt><b>-R</b></dt><dd>Copy file hierarchies.</dd><dt><b>-r</b></dt><dd><sup>[<a href="javascript:open_code('OB')">OB</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Copy file hierarchies. The treatment of special files is implementation-defined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl><p>Specifying more than one of the mutually-exclusive options <b>-H</b>, <b>-L</b>, and <b>-P</b> shall not be considered an error.The last option specified shall determine the behavior of the utility.</p></blockquote><h4><a name="tag_04_27_05"></a>OPERANDS</h4><blockquote><p>The following operands shall be supported:</p><dl compact><dt><i>source_file</i></dt><dd>A pathname of a file to be copied.</dd><dt><i>target_file</i></dt><dd>A pathname of an existing or nonexistent file, used for the output when a single file is copied.</dd><dt><i>target</i></dt><dd>A pathname of a directory to contain the copied files.</dd></dl></blockquote><h4><a name="tag_04_27_06"></a>STDIN</h4><blockquote><p>The standard input shall be used to read an input line in response to each prompt specified in the STDERR section. Otherwise,the standard input shall not be used.</p></blockquote><h4><a name="tag_04_27_07"></a>INPUT FILES</h4><blockquote><p>The input files specified as operands may be of any file type.</p></blockquote><h4><a name="tag_04_27_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>cp</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_COLLATE</i></dt><dd><br>Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extendedregular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files) and the behavior of character classes used in the extended regularexpression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale for the processing of affirmative responses that should be used to affect the format and contents ofdiagnostic messages written to standard error.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_27_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_27_10"></a>STDOUT</h4><blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_27_11"></a>STDERR</h4><blockquote><p>A prompt shall be written to standard error under the conditions specified in the DESCRIPTION section. The prompt shall containthe destination pathname, but its format is otherwise unspecified. Otherwise, the standard error shall be used only for diagnosticmessages.</p></blockquote><h4><a name="tag_04_27_12"></a>OUTPUT FILES</h4><blockquote><p>The output files may be of any type.</p></blockquote><h4><a name="tag_04_27_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_27_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt>&nbsp;0</dt><dd>All files were copied successfully.</dd><dt>&gt;0</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_27_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>If <i>cp</i> is prematurely terminated by a signal or error, files or file hierarchies may be only partially copied and filesand directories may have incorrect permissions or access and modification times.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_27_16"></a>APPLICATION USAGE</h4><blockquote><p>The difference between <b>-R</b> and <b>-r</b> is in the treatment by <i>cp</i> of file types other than regular and directory.The original <b>-r</b> flag, for historic reasons, does not handle special files any differently from regular files, but alwaysreads the file and copies its contents. This has obvious problems in the presence of special file types; for example, characterdevices, FIFOs, and sockets. The <b>-R</b> option is intended to recreate the file hierarchy and the <b>-r</b> option supportshistorical practice. It was anticipated that a future version of this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 would deprecate the<b>-r</b> option, and for that reason, there has been no attempt to fix its behavior with respect to FIFOs or other file typeswhere copying the file is clearly wrong. However, some implementations support <b>-r</b> with the same abilities as the <b>-R</b>defined in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001. To accommodate them as well as systems that do not, the differencesbetween <b>-r</b> and <b>-R</b> are implementation-defined. Implementations may make them identical. The <b>-r</b> option is markedobsolescent.</p><p>The set-user-ID and set-group-ID bits are explicitly cleared when files are created. This is to prevent users from creatingprograms that are set-user-ID or set-group-ID to them when copying files or to make set-user-ID or set-group-ID files accessible tonew groups of users. For example, if a file is set-user-ID and the copy has a different group ID than the source, a new group ofusers has execute permission to a set-user-ID program than did previously. In particular, this is a problem for superusers copyingusers' trees.</p></blockquote><h4><a name="tag_04_27_17"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_27_18"></a>RATIONALE</h4><blockquote><p>The <b>-i</b> option exists on BSD systems, giving applications and users a way to avoid accidentally removing files whencopying. Although the 4.3 BSD version does not prompt if the standard input is not a terminal, the standard developers decided thatuse of <b>-i</b> is a request for interaction, so when the destination path exists, the utility takes instructions from whateverresponds on standard input.</p><p>The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specifiedbecause implementations may desire more descriptive prompts than those used on historical implementations. Therefore, anapplication using the <b>-i</b> option relies on the system to provide the most suitable dialog directly with the user, based onthe behavior specified.</p><p>The <b>-p</b> option is historical practice on BSD systems, duplicating the time of last data modification and time of lastaccess. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 extends it to preserve the user and group IDs, as well as the filepermissions. This requirement has obvious problems in that the directories are almost certainly modified after being copied. Thisvolume of IEEE&nbsp;Std&nbsp;1003.1-2001 requires that the modification times be preserved. The statement that the order in whichthe characteristics are duplicated is unspecified is to permit implementations to provide the maximum amount of security for theuser. Implementations should take into account the obvious security issues involved in setting the owner, group, and mode in thewrong order or creating files with an owner, group, or mode different from the final value.</p><p>It is unspecified whether <i>cp</i> writes diagnostic messages when the user and group IDs cannot be set due to the widespreadpractice of users using <b>-p</b> to duplicate some portion of the file characteristics, indifferent to the duplication of others.Historic implementations only write diagnostic messages on errors other than [EPERM].</p><p>The <b>-r</b> option is historical practice on BSD and BSD-derived systems, copying file hierarchies as opposed to single files.This functionality is used heavily in historical applications, and its loss would significantly decrease consensus. The <b>-R</b>option was added as a close synonym to the <b>-r</b> option, selected for consistency with all other options in this volume ofIEEE&nbsp;Std&nbsp;1003.1-2001 that do recursive directory descent.</p><p>When a failure occurs during the copying of a file hierarchy, <i>cp</i> is required to attempt to copy files that are on thesame level in the hierarchy or above the file where the failure occurred. It is unspecified if <i>cp</i> shall attempt to copyfiles below the file where the failure occurred (which cannot succeed in any case).</p><p>Permissions, owners, and groups of created special file types have been deliberately left as implementation-defined. This is toallow systems to satisfy special requirements (for example, allowing users to create character special devices, but requiring themto be owned by a certain group). In general, it is strongly suggested that the permissions, owner, and group be the same as if theuser had run the historical <i>mknod</i>, <a href="../utilities/ln.html"><i>ln</i></a>, or other utility to create the file. It isalso probable that additional privileges are required to create block, character, or other implementation-defined special filetypes.</p><p>Additionally, the <b>-p</b> option explicitly requires that all set-user-ID and set-group-ID permissions be discarded if any ofthe owner or group IDs cannot be set. This is to keep users from unintentionally giving away special privilege when copyingprograms.</p><p>When creating regular files, historical versions of <i>cp</i> use the mode of the source file as modified by the file modecreation mask. Other choices would have been to use the mode of the source file unmodified by the creation mask or to use the samemode as would be given to a new file created by the user (plus the execution bits of the source file) and then modify it by thefile mode creation mask. In the absence of any strong reason to change historic practice, it was in large part retained.</p><p>When creating directories, historical versions of <i>cp</i> use the mode of the source directory, plus read, write, and searchbits for the owner, as modified by the file mode creation mask. This is done so that <i>cp</i> can copy trees where the user hasread permission, but the owner does not. A side effect is that if the file creation mask denies the owner permissions, <i>cp</i>fails. Also, once the copy is done, historical versions of <i>cp</i> set the permissions on the created directory to be the same asthe source directory, unmodified by the file creation mask.</p><p>This behavior has been modified so that <i>cp</i> is always able to create the contents of the directory, regardless of the filecreation mask. After the copy is done, the permissions are set to be the same as the source directory, as modified by the filecreation mask. This latter change from historical behavior is to prevent users from accidentally creating directories withpermissions beyond those they would normally set and for consistency with the behavior of <i>cp</i> in creating files.</p><p>It is not a requirement that <i>cp</i> detect attempts to copy a file to itself; however, implementations are stronglyencouraged to do so. Historical implementations have detected the attempt in most cases.</p><p>There are two methods of copying subtrees in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001. The other method is described aspart of the <a href="../utilities/pax.html"><i>pax</i></a> utility (see <a href="pax.html"><i>pax</i></a> ). Both methods arehistorical practice. The <i>cp</i> utility provides a simpler, more intuitive interface, while <a href="../utilities/pax.html"><i>pax</i></a> offers a finer granularity of control. Each provides additional functionality to the other;in particular, <a href="../utilities/pax.html"><i>pax</i></a> maintains the hard-link structure of the hierarchy, while <i>cp</i>does not. It is the intention of the standard developers that the results be similar (using appropriate option combinations in bothutilities). The results are not required to be identical; there seemed insufficient gain to applications to balance the difficultyof implementations having to guarantee that the results would be exactly identical.</p><p>The wording allowing <i>cp</i> to copy a directory to implementation-defined file types not specified by the System Interfacesvolume of IEEE&nbsp;Std&nbsp;1003.1-2001 is provided so that implementations supporting symbolic links are not required to prohibitcopying directories to symbolic links. Other extensions to the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001 filetypes may need to use this loophole as well.</p></blockquote><h4><a name="tag_04_27_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>The <b>-r</b> option may be removed; use <b>-R</b> instead.</p></blockquote><h4><a name="tag_04_27_20"></a>SEE ALSO</h4><blockquote><p><a href="mv.html"><i>mv</i></a> , <a href="find.html"><i>find</i></a> , <a href="ln.html"><i>ln</i></a> , <a href="pax.html"><i>pax</i></a> , the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../functions/open.html"><i>open</i>()</a>, <a href="../functions/unlink.html"><i>unlink</i>()</a></p></blockquote><h4><a name="tag_04_27_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_27_22"></a>Issue 6</h4><blockquote><p>The <b>-r</b> option is marked obsolescent.</p><p>The new options <b>-H</b>, <b>-L</b>, and <b>-P</b> are added to align with the IEEE&nbsp;P1003.2b draft standard. These optionsaffect the processing of symbolic links.</p><p>IEEE PASC Interpretation 1003.2 #194 is applied, adding a description of the <b>-P</b> option.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/18 is applied, correcting an error in the SEE ALSO section.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -