📄 cp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>cp</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="cp"></a> <a name="tag_04_27"></a><!-- cp --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_27_01"></a>NAME</h4><blockquote>cp - copy files</blockquote><h4><a name="tag_04_27_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>cp</tt> <b>[</b><tt>-fip</tt><b>]</b> <i>source_file target_file</i><tt><br><br>cp</tt> <b>[</b><tt>-fip</tt><b>]</b> <i>source_file</i> <tt>...</tt> <i>target</i><tt><br><br>cp -R</tt> <b>[</b><tt>-H | -L | -P</tt><b>][</b><tt>-fip</tt><b>]</b> <i>source_file</i> <tt>...</tt> <i>target</i><tt><br><br><sup>[<a href="javascript:open_code('OB')">OB</a>]</sup> cp <img src="../images/opt-start.gif" border="0">-r<img src="../images/opt-end.gif" border="0"></tt> <b>[</b><tt>-H | -L | -P</tt><b>][</b><tt>-fip</tt><b>]</b> <i>source_file</i><tt>...</tt> <i>target</i><tt><br></tt></code></p></blockquote><h4><a name="tag_04_27_03"></a>DESCRIPTION</h4><blockquote><p>The first synopsis form is denoted by two operands, neither of which are existing files of type directory. The <i>cp</i> utilityshall copy the contents of <i>source_file</i> (or, if <i>source_file</i> is a file of type symbolic link, the contents of the filereferenced by <i>source_file</i>) to the destination path named by <i>target_file.</i></p><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 thefirst synopsis form is not applicable. It shall be 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 System Interfaces volume of IEEE Std 1003.1-2001,but is not a file of type directory. The <i>cp</i> utility shall copy the contents of each <i>source_file</i> (or, if<i>source_file</i> is a file of type symbolic link, the contents of the file referenced by <i>source_file</i>) to the destinationpath named by the concatenation of <i>target</i>, a slash character, and the last component of <i>source_file</i>.</p><p>The third and fourth synopsis forms are denoted by two or more operands where the <b>-R</b> or <b>-r</b> options are specified.The <i>cp</i> utility shall copy each file in the file hierarchy rooted in each <i>source_file</i> to a destination path named asfollows:</p><ul><li><p>If <i>target</i> exists and is a file of type directory, the name of the corresponding destination path for each file in thefile hierarchy shall be the concatenation of <i>target</i>, a slash character, and the pathname of the file relative to thedirectory containing <i>source_file</i>.</p></li><li><p>If <i>target</i> does not exist and two operands are specified, the name of the corresponding destination path for<i>source_file</i> shall be <i>target</i>; the name of the corresponding destination path for all other files in the file hierarchyshall be the concatenation of <i>target</i>, a slash character, and the pathname of the file relative to <i>source_file</i>.</p></li></ul><p>It shall be an error if <i>target</i> does not exist and more than two operands are specified, or if <i>target</i> exists and isa file of a type defined by the System Interfaces volume of IEEE Std 1003.1-2001, but is not a file of typedirectory.</p><p>In the following description, the term <i>dest_file</i> refers to the file named by the destination path. The term<i>source_file</i> refers to the file that is being copied, whether specified as an operand or a file in a file hierarchy rooted ina <i>source_file</i> operand. If <i>source_file</i> is a file of type symbolic link:</p><ul><li><p>If neither the <b>-R</b> nor <b>-r</b> options were specified, <i>cp</i> shall take actions based on the type and contents ofthe file referenced by the symbolic link, and not by the symbolic link itself.</p></li><li><p>If the <b>-R</b> option was specified:</p><ul><li><p>If none of the options <b>-H</b>, <b>-L</b>, nor <b>-P</b> were specified, it is unspecified which of <b>-H</b>, <b>-L</b>, or<b>-P</b> will be used as a default.</p></li><li><p>If the <b>-H</b> option was specified, <i>cp</i> shall take actions based on the type and contents of the file referenced by anysymbolic link specified as a <i>source_file</i> operand.</p></li><li><p>If the <b>-L</b> option was specified, <i>cp</i> shall take actions based on the type and contents of the file referenced by anysymbolic link specified as a <i>source_file</i> operand or any symbolic links encountered during traversal of a file hierarchy.</p></li><li><p>If the <b>-P</b> option was specified, <i>cp</i> shall copy any symbolic link specified as a <i>source_file</i> operand and anysymbolic links encountered during traversal of a file hierarchy, and shall not follow any symbolic links.</p></li></ul></li><li><p>If the <b>-r</b> option was specified, the behavior is implementation-defined.</p></li></ul><p>For each <i>source_file</i>, the following steps shall be taken:</p><ol><li><p>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 shall do nothing more with <i>source_file</i> and shall go on to any remaining files.</p></li><li><p>If <i>source_file</i> is of type directory, the following steps shall be taken:</p><ol type="a"><li><p>If neither the <b>-R</b> or <b>-r</b> options were specified, <i>cp</i> shall write a diagnostic message to standard error, donothing more with <i>source_file</i>, and go on to any remaining files.</p></li><li><p>If <i>source_file</i> was not specified as an operand and <i>source_file</i> is dot or dot-dot, <i>cp</i> shall do nothing morewith <i>source_file</i> and go on to any remaining files.</p></li><li><p>If <i>dest_file</i> exists and it is a file type not specified by the System Interfaces volume ofIEEE Std 1003.1-2001, the behavior is implementation-defined.</p></li><li><p>If <i>dest_file</i> exists and it is not of type directory, <i>cp</i> shall write a diagnostic message to standard error, donothing more with <i>source_file</i> or any files below <i>source_file</i> in the file hierarchy, and go on to any remainingfiles.</p></li><li><p>If the directory <i>dest_file</i> does not exist, it shall be created with file permission bits set to the same value as thoseof <i>source_file</i>, modified by the file creation mask of the user if the <b>-p</b> option was not specified, and thenbitwise-inclusively OR'ed with S_IRWXU. If <i>dest_file</i> cannot be created, <i>cp</i> shall write a diagnostic message tostandard error, do nothing more with <i>source_file</i>, and go on to any remaining files. It is unspecified if <i>cp</i> attemptsto copy files in the file hierarchy rooted in <i>source_file</i>.</p></li><li><p>The files in the directory <i>source_file</i> shall be copied to the directory <i>dest_file</i>, taking the four steps (1 to 4)listed here with the files as <i>source_file</i>s.</p></li><li><p>If <i>dest_file</i> was created, its file permission bits shall 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><li><p>The <i>cp</i> utility shall do nothing more with <i>source_file</i> and go on to any remaining files.</p></li></ol></li><li><p>If <i>source_file</i> is of type regular file, the following steps shall be taken:</p><ol type="a"><li><p>If <i>dest_file</i> exists, the following steps shall be taken:</p><ol type="i"><li><p>If the <b>-i</b> option is in effect, the <i>cp</i> utility shall write a prompt to the standard error and read a line from thestandard input. If the response is not affirmative, <i>cp</i> shall do nothing more with <i>source_file</i> and go on to anyremaining files.</p></li><li><p>A file descriptor for <i>dest_file</i> shall be obtained by performing actions equivalent to the <a href="../functions/open.html"><i>open</i>()</a> function defined in the System Interfaces volume of IEEE Std 1003.1-2001called 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><li><p>If the attempt to obtain a file descriptor fails and the <b>-f</b> option is in effect, <i>cp</i> shall attempt to remove thefile by performing actions equivalent to the <a href="../functions/unlink.html"><i>unlink</i>()</a> function defined in the SystemInterfaces volume of IEEE Std 1003.1-2001 called using <i>dest_file</i> as the <i>path</i> argument. If this attemptsucceeds, <i>cp</i> shall continue with step 3b.</p></li></ol></li><li><p>If <i>dest_file</i> does not exist, a file descriptor shall be obtained by performing actions equivalent to the <a href="../functions/open.html"><i>open</i>()</a> function defined in the System Interfaces volume of IEEE Std 1003.1-2001called using <i>dest_file</i> as the <i>path</i> argument, and the bitwise-inclusive OR of O_WRONLY and O_CREAT as the <i>oflag</i>argument. The file permission bits of <i>source_file</i> shall be the <i>mode</i> argument.</p></li><li><p>If the attempt to obtain a file descriptor fails, <i>cp</i> shall write a diagnostic message to standard error, do nothing morewith <i>source_file</i>, and go on to any remaining files.</p></li><li><p>The contents of <i>source_file</i> shall be written to the file descriptor. Any write errors shall cause <i>cp</i> to write adiagnostic message to standard error and continue to step 3e.</p></li><li><p>The file descriptor shall be closed.</p></li><li><p>The <i>cp</i> utility shall do nothing more with <i>source_file</i>. If a write error occurred in step 3d, it is unspecified if<i>cp</i> continues with any remaining files. If no write error occurred in step 3d, <i>cp</i> shall go on to any remainingfiles.</p></li></ol></li><li><p>Otherwise, the following steps shall be taken:</p><ol type="a"><li><p>If the <b>-r</b> option was specified, the behavior is implementation-defined.</p></li><li><p>If the <b>-R</b> option was specified, the following steps shall be taken:</p><ol type="i"><li><p>The <i>dest_file</i> shall be created with the same file type as <i>source_file</i>.</p></li><li><p>If <i>source_file</i> is a file of type FIFO, the file permission bits shall 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. Otherwise, the permissions, owner ID, andgroup ID of <i>dest_file</i> are implementation-defined.</p><p>If this creation fails for any reason, <i>cp</i> shall write a diagnostic message to standard error, do nothing more with<i>source_file</i>, and go on to any remaining files.</p></li><li><p>If <i>source_file</i> is a file of type symbolic link, the pathname contained in <i>dest_file</i> shall be the same as thepathname contained in <i>source_file</i>.</p><p>If this fails for any reason, <i>cp</i> shall write a diagnostic message to standard error, do nothing more with<i>source_file</i>, and go on to any remaining files.</p></li></ol></li></ol></li></ol><p>If the implementation provides additional or alternate access control mechanisms (see the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap04.html#tag_04_04">Section 4.4, File Access Permissions</a>), theireffect on copies of files is implementation-defined.</p></blockquote><h4><a name="tag_04_27_04"></a>OPTIONS</h4><blockquote><p>The <i>cp</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-f</b></dt><dd>If a file descriptor for a destination file cannot be obtained, as described in step 3.a.ii., attempt to unlink the destinationfile and proceed.</dd><dt><b>-H</b></dt><dd>Take actions based on the type and contents of the file referenced by any symbolic link specified as a <i>source_file</i>operand.</dd><dt><b>-i</b></dt><dd>Write a prompt to standard error before copying to any existing destination file. If the response from the standard input isaffirmative, the copy shall be attempted; otherwise, it shall not.</dd><dt><b>-L</b></dt><dd>Take actions based on the type and contents of the file referenced by any symbolic link specified as a <i>source_file</i>operand or any symbolic links encountered during traversal of a file hierarchy.</dd><dt><b>-P</b></dt><dd>Take actions on any symbolic link specified as a <i>source_file</i> operand or any symbolic link encountered during traversalof a file hierarchy.</dd><dt><b>-p</b></dt><dd>Duplicate the following characteristics of each source file in the corresponding destination file: <ol><li><p>The time of last data modification and time of last access. If this duplication fails for any reason, <i>cp</i> shall write adiagnostic message to standard error.</p></li><li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -