408 lines
16 KiB
HTML
408 lines
16 KiB
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 The Open Group, All Rights Reserved -->
|
|
<title>rm</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="rm"></a> <a name="tag_04_121"></a><!-- rm -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_121_01"></a>NAME</h4>
|
|
|
|
<blockquote>rm - remove directory entries</blockquote>
|
|
|
|
<h4><a name="tag_04_121_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>rm</tt> <b>[</b><tt>-fiRr</tt><b>]</b> <i>file</i><tt>...</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>rm</i> utility shall remove the directory entry specified by each <i>file</i> argument.</p>
|
|
|
|
<p>If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname
|
|
component), <i>rm</i> shall write a diagnostic message to standard error and do nothing more with such operands.</p>
|
|
|
|
<p>For each <i>file</i> the following steps shall be taken:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>If the <i>file</i> does not exist:</p>
|
|
|
|
<ol type="a">
|
|
<li>
|
|
<p>If the <b>-f</b> option is not specified, <i>rm</i> shall write a diagnostic message to standard error.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Go on to any remaining <i>files</i>.</p>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If <i>file</i> is of type directory, the following steps shall be taken:</p>
|
|
|
|
<ol type="a">
|
|
<li>
|
|
<p>If neither the <b>-R</b> option nor the <b>-r</b> option is specified, <i>rm</i> shall write a diagnostic message to standard
|
|
error, do nothing more with <i>file</i>, and go on to any remaining files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the <b>-f</b> option is not specified, and either the permissions of <i>file</i> do not permit writing and the standard input
|
|
is a terminal or the <b>-i</b> option is specified, <i>rm</i> shall write a prompt to standard error and read a line from the
|
|
standard input. If the response is not affirmative, <i>rm</i> shall do nothing more with the current file and go on to any
|
|
remaining files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>For each entry contained in <i>file</i>, other than dot or dot-dot, the four steps listed here (1 to 4) shall be taken with the
|
|
entry as if it were a <i>file</i> operand. The <i>rm</i> utility shall not traverse directories by following symbolic links into
|
|
other parts of the hierarchy, but shall remove the links themselves.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the <b>-i</b> option is specified, <i>rm</i> shall write a prompt to standard error and read a line from the standard input.
|
|
If the response is not affirmative, <i>rm</i> shall do nothing more with the current file, and go on to any remaining files.</p>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If <i>file</i> is not of type directory, the <b>-f</b> option is not specified, and either the permissions of <i>file</i> do not
|
|
permit writing and the standard input is a terminal or the <b>-i</b> option is specified, <i>rm</i> shall write a prompt to the
|
|
standard error and read a line from the standard input. If the response is not affirmative, <i>rm</i> shall do nothing more with
|
|
the current file and go on to any remaining files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the current file is a directory, <i>rm</i> shall perform actions equivalent to the <a href=
|
|
"../functions/rmdir.html"><i>rmdir</i>()</a> function defined in the System Interfaces volume of IEEE Std 1003.1-2001
|
|
called with a pathname of the current file used as the <i>path</i> argument. If the current file is not a directory, <i>rm</i>
|
|
shall perform actions equivalent to the <a href="../functions/unlink.html"><i>unlink</i>()</a> function defined in the System
|
|
Interfaces volume of IEEE Std 1003.1-2001 called with a pathname of the current file used as the <i>path</i>
|
|
argument.</p>
|
|
|
|
<p>If this fails for any reason, <i>rm</i> shall write a diagnostic message to standard error, do nothing more with the current
|
|
file, and go on to any remaining files.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>The <i>rm</i> utility shall be able to descend to arbitrary depths in a file hierarchy, and shall not fail due to path length
|
|
limitations (unless an operand specified by the user exceeds system limitations).</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>rm</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>Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands.
|
|
Any previous occurrences of the <b>-i</b> option shall be ignored.</dd>
|
|
|
|
<dt><b>-i</b></dt>
|
|
|
|
<dd>Prompt for confirmation as described previously. Any previous occurrences of the <b>-f</b> option shall be ignored.</dd>
|
|
|
|
<dt><b>-R</b></dt>
|
|
|
|
<dd>Remove file hierarchies. See the DESCRIPTION.</dd>
|
|
|
|
<dt><b>-r</b></dt>
|
|
|
|
<dd>Equivalent to <b>-R</b>.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operand shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>file</i></dt>
|
|
|
|
<dd>A pathname of a directory entry to be removed.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_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 STDOUT section. Otherwise,
|
|
the standard input shall not be used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_121_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>rm</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 of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the 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 extended
|
|
regular 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 as
|
|
opposed to multi-byte characters in arguments) and the behavior of character classes within regular expressions used in the
|
|
extended regular expression 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 of
|
|
diagnostic 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_121_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<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 prompts
|
|
shall contain the <i>file</i> pathname, but their format is otherwise unspecified. The standard error also shall be used for
|
|
diagnostic 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 doing
|
|
something 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 of
|
|
IEEE 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 in
|
|
the 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 for
|
|
confirmation, 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 specified
|
|
because implementations may desire more descriptive prompts than those used on historical implementations. Therefore, an
|
|
application not using the <b>-f</b> option, or using the <b>-i</b> option, relies on the system to provide the most suitable dialog
|
|
directly 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 with
|
|
the other utilities in this volume of IEEE Std 1003.1-2001 that provide options requesting recursive descent through the
|
|
file 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" the
|
|
unlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodified
|
|
for nonexistent operands and files that cannot be unlinked. In some versions, however, the <b>-f</b> option suppresses usage
|
|
messages 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 is
|
|
historical practice, this volume of IEEE Std 1003.1-2001 does not permit the <b>-f</b> option to suppress such
|
|
messages.</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, once
|
|
before removing its contents and once before actually attempting to delete the directory entry that names it. This allows the user
|
|
to "prune" the file hierarchy walk. Historical versions of <i>rm</i> were inconsistent in that some did not do the former prompt
|
|
for directories named on the command line and others had obscure prompting behavior when the <b>-i</b> option was specified and the
|
|
permissions of the file did not permit writing. The POSIX Shell and Utilities <i>rm</i> differs little from historic practice, but
|
|
does require that prompts be consistent. Historical versions of <i>rm</i> were also inconsistent in that prompts were done to both
|
|
standard 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 allow
|
|
historical 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, for
|
|
example, that the <i>rm</i> utility cannot run out of file descriptors during its descent (that is, if the number of file
|
|
descriptors is limited, <i>rm</i> cannot be implemented in the historical fashion where one file descriptor is used per directory
|
|
level). Also, <i>rm</i> is not permitted to fail because of path length restrictions, unless an operand specified by the user is
|
|
longer 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>
|
|
|