📄 rm.html
字号:
<blockquote><p>Default.</p></blockquote><h4><a name="tag_04_121_10"></a>STDOUT</h4><blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_121_11"></a>STDERR</h4><blockquote><p>Prompts shall be written to standard error under the conditions specified in the DESCRIPTION and OPTIONS sections. The promptsshall contain the <i>file</i> pathname, but their format is otherwise unspecified. The standard error also shall be used fordiagnostic messages.</p></blockquote><h4><a name="tag_04_121_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_121_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_121_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt> 0</dt><dd>All of the named directory entries for which <i>rm</i> performed actions equivalent to the <a href="../functions/rmdir.html"><i>rmdir</i>()</a> or <a href="../functions/unlink.html"><i>unlink</i>()</a> functions were removed.</dd><dt>>0</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_121_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>Default.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_121_16"></a>APPLICATION USAGE</h4><blockquote><p>The <i>rm</i> utility is forbidden to remove the names dot and dot-dot in order to avoid the consequences of inadvertently doingsomething like:</p><pre><tt>rm -r .*</tt></pre><p>Some implementations do not permit the removal of the last link to an executable binary file that is being executed; see the[EBUSY] error in the <a href="../functions/unlink.html"><i>unlink</i>()</a> function defined in the System Interfaces volume ofIEEE Std 1003.1-2001. Thus, the <i>rm</i> utility can fail to remove such files.</p><p>The <b>-i</b> option causes <i>rm</i> to prompt and read the standard input even if the standard input is not a terminal, but inthe absence of <b>-i</b> the mode prompting is not done when the standard input is not a terminal.</p></blockquote><h4><a name="tag_04_121_17"></a>EXAMPLES</h4><blockquote><ol><li><p>The following command:</p><pre><tt>rm a.out core</tt></pre><p>removes the directory entries: <b>a.out</b> and <b>core</b>.</p></li><li><p>The following command:</p><pre><tt>rm -Rf junk</tt></pre><p>removes the directory <b>junk</b> and all its contents, without prompting.</p></li></ol></blockquote><h4><a name="tag_04_121_18"></a>RATIONALE</h4><blockquote><p>For absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of <i>rm</i> describing the behavior when prompting forconfirmation, should be interpreted in the following manner:</p><pre><tt>if ((NOT f_option) AND ((not_writable AND input_is_terminal) OR i_option))</tt></pre><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 not using the <b>-f</b> option, or using the <b>-i</b> option, relies on the system to provide the most suitable dialogdirectly with the user, based on the behavior specified.</p><p>The <b>-r</b> option is historical practice on all known systems. The synonym <b>-R</b> option is provided for consistency withthe other utilities in this volume of IEEE Std 1003.1-2001 that provide options requesting recursive descent through thefile hierarchy.</p><p>The behavior of the <b>-f</b> option in historical versions of <i>rm</i> is inconsistent. In general, along with "forcing" theunlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodifiedfor nonexistent operands and files that cannot be unlinked. In some versions, however, the <b>-f</b> option suppresses usagemessages and system errors as well. Suppressing such messages is not a service to either shell scripts or users.</p><p>It is less clear that error messages regarding files that cannot be unlinked (removed) should be suppressed. Although this ishistorical practice, this volume of IEEE Std 1003.1-2001 does not permit the <b>-f</b> option to suppress suchmessages.</p><p>When given the <b>-r</b> and <b>-i</b> options, historical versions of <i>rm</i> prompt the user twice for each directory, oncebefore removing its contents and once before actually attempting to delete the directory entry that names it. This allows the userto "prune" the file hierarchy walk. Historical versions of <i>rm</i> were inconsistent in that some did not do the former promptfor directories named on the command line and others had obscure prompting behavior when the <b>-i</b> option was specified and thepermissions of the file did not permit writing. The POSIX Shell and Utilities <i>rm</i> differs little from historic practice, butdoes require that prompts be consistent. Historical versions of <i>rm</i> were also inconsistent in that prompts were done to bothstandard output and standard error. This volume of IEEE Std 1003.1-2001 requires that prompts be done to standard error,for consistency with <a href="../utilities/cp.html"><i>cp</i></a> and <a href="../utilities/mv.html"><i>mv</i></a>, and to allowhistorical extensions to <i>rm</i> that provide an option to list deleted files on standard output.</p><p>The <i>rm</i> utility is required to descend to arbitrary depths so that any file hierarchy may be deleted. This means, forexample, that the <i>rm</i> utility cannot run out of file descriptors during its descent (that is, if the number of filedescriptors is limited, <i>rm</i> cannot be implemented in the historical fashion where one file descriptor is used per directorylevel). Also, <i>rm</i> is not permitted to fail because of path length restrictions, unless an operand specified by the user islonger than {PATH_MAX}.</p><p>The <i>rm</i> utility removes symbolic links themselves, not the files they refer to, as a consequence of the dependence on the<a href="../functions/unlink.html"><i>unlink</i>()</a> functionality, per the DESCRIPTION. When removing hierarchies with <b>-r</b>or <b>-R</b>, the prohibition on following symbolic links has to be made explicit.</p></blockquote><h4><a name="tag_04_121_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_121_20"></a>SEE ALSO</h4><blockquote><p><a href="rmdir.html"><i>rmdir</i>()</a> , the System Interfaces volume of IEEE Std 1003.1-2001, <a href="../functions/remove.html"><i>remove</i>()</a>, <a href="../functions/rmdir.html"><i>rmdir</i>()</a>, <a href="../functions/unlink.html"><i>unlink</i>()</a></p></blockquote><h4><a name="tag_04_121_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_121_22"></a>Issue 5</h4><blockquote><p>The FUTURE DIRECTIONS section is added.</p></blockquote><h4><a name="tag_04_121_23"></a>Issue 6</h4><blockquote><p>Text is added to clarify actions relating to symbolic links as specified in the IEEE P1003.2b draft standard.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® 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 + -