Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
rm.html (21376B)
1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved --> 2 <!DOCTYPE HTML> 3 <html lang="en"> 4 <head> 5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 --> 8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved --> 9 <title>rm</title> 10 </head> 11 <body bgcolor="white"> 12 <div class="NAVHEADER"> 13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 14 <tr class="nav"> 15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/renice.html" accesskey="P"><<< 16 Previous</a></td> 17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/rmdel.html" accesskey="N">Next 19 >>></a></td> 20 </tr> 21 </table> 22 <hr align="left" width="100%"></div> 23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 24 <center><font size="2">The Open Group Base Specifications Issue 8<br> 25 IEEE Std 1003.1-2024<br> 26 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 27 <hr size="2" noshade> 28 <a name="top" id="top"></a> <a name="rm" id="rm"></a> <a name="tag_20_104" id="tag_20_104"></a><!-- rm --> 29 <h4 class="mansect"><a name="tag_20_104_01" id="tag_20_104_01"></a>NAME</h4> 30 <blockquote>rm — remove directory entries</blockquote> 31 <h4 class="mansect"><a name="tag_20_104_02" id="tag_20_104_02"></a>SYNOPSIS</h4> 32 <blockquote class="synopsis"> 33 <p><code><tt>rm</tt> <b>[</b><tt>-diRrv</tt><b>]</b> <i>file</i><tt>...<br> 34 <br> 35 rm -f</tt> <b>[</b><tt>-diRrv</tt><b>]</b> <b>[</b><i>file</i><tt>...</tt><b>]</b> <tt><br></tt></code></p> 36 </blockquote> 37 <h4 class="mansect"><a name="tag_20_104_03" id="tag_20_104_03"></a>DESCRIPTION</h4> 38 <blockquote> 39 <p>The <i>rm</i> utility shall remove the directory entry specified by each <i>file</i> argument.</p> 40 <p>If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname 41 component) or if an operand resolves to the root directory, <i>rm</i> shall write a diagnostic message to standard error and do 42 nothing more with such operands.</p> 43 <p>For each <i>file</i> the following steps shall be taken:</p> 44 <ol> 45 <li> 46 <p>If the <i>file</i> does not exist:</p> 47 <ol type="a"> 48 <li> 49 <p>If the <b>-f</b> option is not specified, <i>rm</i> shall write a diagnostic message to standard error.</p> 50 </li> 51 <li> 52 <p>Go on to any remaining <i>files</i>.</p> 53 </li> 54 </ol> 55 </li> 56 <li> 57 <p>If <i>file</i> is of type directory, the following steps shall be taken:</p> 58 <ol type="a"> 59 <li> 60 <p>If neither the <b>-R</b> option nor the <b>-r</b> option is specified, but <b>-d</b> is specified, <i>rm</i> shall proceed with 61 step 3 for the current file. If none of <b>-r</b>, <b>-R</b>, or <b>-d</b> is specified, <i>rm</i> shall write a diagnostic message 62 to standard error, do nothing more with <i>file</i>, and go on to any remaining files.</p> 63 </li> 64 <li> 65 <p>If <i>file</i> is an empty directory, <i>rm</i> may skip to step 2d. If the <b>-f</b> option is not specified, and either the 66 permissions of <i>file</i> do not permit writing and the standard input is a terminal or the <b>-i</b> option is specified, 67 <i>rm</i> shall write a prompt to standard error and read a line from the standard input. If the response is not affirmative, 68 <i>rm</i> shall do nothing more with the current file and go on to any remaining files.</p> 69 </li> 70 <li> 71 <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 72 entry as if it were a <i>file</i> operand. The <i>rm</i> utility shall not traverse directories by following symbolic links into 73 other parts of the hierarchy, but shall remove the links themselves.</p> 74 </li> 75 <li> 76 <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. 77 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> 78 </li> 79 <li> 80 <p><i>rm</i> shall proceed with step 4 for the current file.</p> 81 </li> 82 </ol> 83 </li> 84 <li> 85 <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 86 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 87 standard input. If the response is not affirmative, <i>rm</i> shall do nothing more with the current file and go on to any 88 remaining files.</p> 89 </li> 90 <li> 91 <p><i>rm</i> shall perform actions equivalent to the <a href="../functions/remove.html"><i>remove</i>()</a> function defined in the 92 System Interfaces volume of POSIX.1-2024 called with a pathname of the current file used as the <i>path</i> argument.</p> 93 <p>If <i>rm</i> successfully performed the above actions on the current file, and the <b>-v</b> option is specified, <i>rm</i> 94 shall write a message containing the pathname of the current file to the standard output. If the actions fail for any reason, 95 <i>rm</i> shall write a diagnostic message to standard error, do nothing more with the current file, and go on to any remaining 96 files.</p> 97 </li> 98 </ol> 99 <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 100 limitations (unless an operand specified by the user exceeds system limitations).</p> 101 </blockquote> 102 <h4 class="mansect"><a name="tag_20_104_04" id="tag_20_104_04"></a>OPTIONS</h4> 103 <blockquote> 104 <p>The <i>rm</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 105 Guidelines</i></a> .</p> 106 <p>The following options shall be supported:</p> 107 <dl compact> 108 <dd></dd> 109 <dt><b>-d</b></dt> 110 <dd>Remove empty directories. See the DESCRIPTION.</dd> 111 <dt><b>-f</b></dt> 112 <dd>Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of no file operands, or 113 in the case of operands that do not exist. Any previous occurrences of the <b>-i</b> option shall be ignored.</dd> 114 <dt><b>-i</b></dt> 115 <dd>Prompt for confirmation as described previously. Any previous occurrences of the <b>-f</b> option shall be ignored.</dd> 116 <dt><b>-R</b></dt> 117 <dd>Remove file hierarchies. See the DESCRIPTION.</dd> 118 <dt><b>-r</b></dt> 119 <dd>Equivalent to <b>-R</b>.</dd> 120 <dt><b>-v</b></dt> 121 <dd>After each file has been removed, write a message to standard output indicating that it has been removed.</dd> 122 </dl> 123 </blockquote> 124 <h4 class="mansect"><a name="tag_20_104_05" id="tag_20_104_05"></a>OPERANDS</h4> 125 <blockquote> 126 <p>The following operand shall be supported:</p> 127 <dl compact> 128 <dd></dd> 129 <dt><i>file</i></dt> 130 <dd>A pathname of a directory entry to be removed.</dd> 131 </dl> 132 </blockquote> 133 <h4 class="mansect"><a name="tag_20_104_06" id="tag_20_104_06"></a>STDIN</h4> 134 <blockquote> 135 <p>The standard input shall be used to read an input line in response to each prompt specified in the STDOUT section. Otherwise, 136 the standard input shall not be used.</p> 137 </blockquote> 138 <h4 class="mansect"><a name="tag_20_104_07" id="tag_20_104_07"></a>INPUT FILES</h4> 139 <blockquote> 140 <p>None.</p> 141 </blockquote> 142 <h4 class="mansect"><a name="tag_20_104_08" id="tag_20_104_08"></a>ENVIRONMENT VARIABLES</h4> 143 <blockquote> 144 <p>The following environment variables shall affect the execution of <i>rm</i>:</p> 145 <dl compact> 146 <dd></dd> 147 <dt><i>LANG</i></dt> 148 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 149 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 150 variables used to determine the values of locale categories.)</dd> 151 <dt><i>LC_ALL</i></dt> 152 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 153 <dt><i>LC_COLLATE</i></dt> 154 <dd><br> 155 Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended 156 regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd> 157 <dt><i>LC_CTYPE</i></dt> 158 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 159 opposed to multi-byte characters in arguments) and the behavior of character classes within regular expressions used in the 160 extended regular expression defined for the <b>yesexpr</b> locale keyword in the <i>LC_MESSAGES</i> category.</dd> 161 <dt><i>LC_MESSAGES</i></dt> 162 <dd><br> 163 Determine the locale used to process affirmative responses, and the locale used to affect the format and contents of diagnostic 164 messages and prompts written to standard error.</dd> 165 <dt><i>NLSPATH</i></dt> 166 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 167 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 168 "0"></dd> 169 </dl> 170 </blockquote> 171 <h4 class="mansect"><a name="tag_20_104_09" id="tag_20_104_09"></a>ASYNCHRONOUS EVENTS</h4> 172 <blockquote> 173 <p>Default.</p> 174 </blockquote> 175 <h4 class="mansect"><a name="tag_20_104_10" id="tag_20_104_10"></a>STDOUT</h4> 176 <blockquote> 177 <p>If the <b>-v</b> option is specified, information about each removed file shall be written to standard output in an unspecified 178 format.</p> 179 </blockquote> 180 <h4 class="mansect"><a name="tag_20_104_11" id="tag_20_104_11"></a>STDERR</h4> 181 <blockquote> 182 <p>Prompts shall be written to standard error under the conditions specified in the DESCRIPTION and OPTIONS sections. The prompts 183 shall contain the <i>file</i> pathname, but their format is otherwise unspecified. The standard error also shall be used for 184 diagnostic messages.</p> 185 </blockquote> 186 <h4 class="mansect"><a name="tag_20_104_12" id="tag_20_104_12"></a>OUTPUT FILES</h4> 187 <blockquote> 188 <p>None.</p> 189 </blockquote> 190 <h4 class="mansect"><a name="tag_20_104_13" id="tag_20_104_13"></a>EXTENDED DESCRIPTION</h4> 191 <blockquote> 192 <p>None.</p> 193 </blockquote> 194 <h4 class="mansect"><a name="tag_20_104_14" id="tag_20_104_14"></a>EXIT STATUS</h4> 195 <blockquote> 196 <p>The following exit values shall be returned:</p> 197 <dl compact> 198 <dd></dd> 199 <dt> 0</dt> 200 <dd>All requested directory entries (excluding directory entries where a non-affirmative response was given to a request for 201 confirmation) were successfully deleted. In addition, if the <b>-v</b> option is specified, information about each removed 202 directory entry was successfully written to standard output.</dd> 203 <dt>>0</dt> 204 <dd>An error occurred.</dd> 205 </dl> 206 </blockquote> 207 <h4 class="mansect"><a name="tag_20_104_15" id="tag_20_104_15"></a>CONSEQUENCES OF ERRORS</h4> 208 <blockquote> 209 <p>Default.</p> 210 </blockquote> 211 <hr> 212 <div class="box"><em>The following sections are informative.</em></div> 213 <h4 class="mansect"><a name="tag_20_104_16" id="tag_20_104_16"></a>APPLICATION USAGE</h4> 214 <blockquote> 215 <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 216 something like:</p> 217 <pre> 218 <tt>rm -r .* 219 </tt></pre> 220 <p>Some implementations do not permit the removal of the last hard link to an executable binary file that is being executed; see 221 the [EBUSY] error in the <a href="../functions/unlink.html"><i>unlink</i>()</a> function defined in the System Interfaces volume of 222 POSIX.1-2024. Thus, the <i>rm</i> utility can fail to remove such files.</p> 223 <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 224 the absence of <b>-i</b> the mode prompting is not done when the standard input is not a terminal.</p> 225 </blockquote> 226 <h4 class="mansect"><a name="tag_20_104_17" id="tag_20_104_17"></a>EXAMPLES</h4> 227 <blockquote> 228 <ol> 229 <li> 230 <p>The following command:</p> 231 <pre> 232 <tt>rm a.out core 233 </tt></pre> 234 <p>removes the directory entries: <b>a.out</b> and <b>core</b>, or issues an error if either directory entry is itself a directory 235 or does not exist.</p> 236 </li> 237 <li> 238 <p>The following command:</p> 239 <pre> 240 <tt>rm -Rf junk 241 </tt></pre> 242 <p>removes the directory <b>junk</b> and all its contents, without prompting.</p> 243 </li> 244 <li> 245 <p>The following command:</p> 246 <pre> 247 <tt>rm -d name 248 </tt></pre> 249 <p>behaves like</p> 250 <pre> 251 <tt>rmdir name 252 </tt></pre> 253 <p>if <b>name</b> is a directory (including failing if <b>name</b> is not empty), as if by the <a href= 254 "../functions/rmdir.html"><i>rmdir</i>()</a> function; and behaves like</p> 255 <pre> 256 <tt>rm name 257 </tt></pre> 258 <p>if <b>name</b> is not a directory, as if by the <a href="../functions/unlink.html"><i>unlink</i>()</a> function.</p> 259 </li> 260 </ol> 261 </blockquote> 262 <h4 class="mansect"><a name="tag_20_104_18" id="tag_20_104_18"></a>RATIONALE</h4> 263 <blockquote> 264 <p>For absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of <i>rm</i> describing the behavior when prompting for 265 confirmation, should be interpreted in the following manner:</p> 266 <pre> 267 <tt>if ((NOT f_option) AND 268 ((not_writable AND input_is_terminal) OR i_option)) 269 </tt></pre> 270 <p>The exact format of the interactive prompts is unspecified. Only the general nature of the contents of prompts are specified 271 because implementations may desire more descriptive prompts than those used on historical implementations. Therefore, an 272 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 273 directly with the user, based on the behavior specified.</p> 274 <p>The <b>-r</b> option is historical practice on all known systems. The synonym <b>-R</b> option is provided for consistency with 275 the other utilities in this volume of POSIX.1-2024 that provide options requesting recursive descent through the file 276 hierarchy.</p> 277 <p>The behavior of the <b>-f</b> option in historical versions of <i>rm</i> is inconsistent. In general, along with "forcing" the 278 unlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodified 279 for nonexistent operands and files that cannot be unlinked. In some versions, however, the <b>-f</b> option suppresses usage 280 messages and system errors as well. Suppressing such messages is not a service to either shell scripts or users.</p> 281 <p>It is less clear that error messages regarding files that cannot be unlinked (removed) should be suppressed. Although this is 282 historical practice, this volume of POSIX.1-2024 does not permit the <b>-f</b> option to suppress such messages.</p> 283 <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 284 before removing its contents and once before actually attempting to delete the directory entry that names it. This allows the user 285 to "prune" the file hierarchy walk. Historical versions of <i>rm</i> were inconsistent in that some did not do the former prompt 286 for directories named on the command line and others had obscure prompting behavior when the <b>-i</b> option was specified and the 287 permissions of the file did not permit writing. The POSIX Shell and Utilities <i>rm</i> differs little from historic practice, but 288 does require that prompts be consistent. Historical versions of <i>rm</i> were also inconsistent in that prompts were done to both 289 standard output and standard error. This volume of POSIX.1-2024 requires that prompts be done to standard error, for consistency 290 with <a href="../utilities/cp.html"><i>cp</i></a> and <a href="../utilities/mv.html"><i>mv</i></a>, and to allow historical 291 extensions to <i>rm</i> that provide an option to list deleted files on standard output.</p> 292 <p>The <i>rm</i> utility is required to descend to arbitrary depths so that any file hierarchy may be deleted. This means, for 293 example, that the <i>rm</i> utility cannot run out of file descriptors during its descent (that is, if the number of file 294 descriptors is limited, <i>rm</i> cannot be implemented in the historical fashion where one file descriptor is used per directory 295 level). Also, <i>rm</i> is not permitted to fail because of path length restrictions, unless an operand specified by the user is 296 longer than {PATH_MAX}.</p> 297 <p>The <i>rm</i> utility removes symbolic links themselves, not the files they refer to, as a consequence of the dependence on the 298 <a href="../functions/unlink.html"><i>unlink</i>()</a> functionality, per the DESCRIPTION. When removing hierarchies with <b>-r</b> 299 or <b>-R</b>, the prohibition on following symbolic links has to be made explicit.</p> 300 <p>The addition of the <b>-d</b> option allows the use of <i>rm</i> to delete either a file or an empty directory without the risk 301 of recursion into a non-empty directory, and without the inherent race between determining a file's type and deciding what action 302 to attempt on that file. If either the <b>-r</b> or <b>-R</b> option is specified, the use of recursion takes precedence.</p> 303 <p>The addition of the <b>-v</b> option allows a user of <i>rm</i> to see which files have been deleted.</p> 304 </blockquote> 305 <h4 class="mansect"><a name="tag_20_104_19" id="tag_20_104_19"></a>FUTURE DIRECTIONS</h4> 306 <blockquote> 307 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a <newline> 308 character when <newline> is a terminator or separator in the output format being used, implementations are encouraged to 309 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p> 310 </blockquote> 311 <h4 class="mansect"><a name="tag_20_104_20" id="tag_20_104_20"></a>SEE ALSO</h4> 312 <blockquote> 313 <p><a href="../utilities/rmdir.html#tag_20_106"><i>rmdir</i></a></p> 314 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href= 315 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p> 316 <p>XSH <a href="../functions/remove.html#"><i>remove</i></a> , <a href="../functions/rmdir.html#tag_17_493"><i>rmdir</i></a> , 317 <a href="../functions/unlink.html#tag_17_649"><i>unlink</i></a></p> 318 </blockquote> 319 <h4 class="mansect"><a name="tag_20_104_21" id="tag_20_104_21"></a>CHANGE HISTORY</h4> 320 <blockquote> 321 <p>First released in Issue 2.</p> 322 </blockquote> 323 <h4 class="mansect"><a name="tag_20_104_22" id="tag_20_104_22"></a>Issue 5</h4> 324 <blockquote> 325 <p>The FUTURE DIRECTIONS section is added.</p> 326 </blockquote> 327 <h4 class="mansect"><a name="tag_20_104_23" id="tag_20_104_23"></a>Issue 6</h4> 328 <blockquote> 329 <p>Text is added to clarify actions relating to symbolic links as specified in the IEEE P1003.2b draft standard.</p> 330 </blockquote> 331 <h4 class="mansect"><a name="tag_20_104_24" id="tag_20_104_24"></a>Issue 7</h4> 332 <blockquote> 333 <p>Austin Group Interpretations 1003.1-2001 #019 and #091 are applied.</p> 334 <p>Austin Group Interpretation 1003.1-2001 #126 is applied, changing the description of the <i>LC_MESSAGES</i> environment 335 variable.</p> 336 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0163 [542], XCU/TC2-2008/0164 [819], and XCU/TC2-2008/0165 [542] are 337 applied.</p> 338 </blockquote> 339 <h4 class="mansect"><a name="tag_20_104_25" id="tag_20_104_25"></a>Issue 8</h4> 340 <blockquote> 341 <p>Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a 342 pathname that contains any bytes that have the encoded value of a <newline> character when <newline> is a terminator or 343 separator in the output format being used.</p> 344 <p>Austin Group Defect 802 is applied, adding the <b>-d</b> option.</p> 345 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 346 <p>Austin Group Defects 1154, 1365, and 1487 are applied, adding the <b>-v</b> option.</p> 347 <p>Austin Group Defect 1380 is applied, changing "last link" to "last hard link".</p> 348 <p>Austin Group Defect 1732 is applied, changing the EXIT STATUS section.</p> 349 </blockquote> 350 <div class="box"><em>End of informative text.</em></div> 351 <hr> 352 <p> </p> 353 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 354 <hr size="2" noshade> 355 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 356 POSIX™ is a Trademark of The IEEE.<br> 357 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 358 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 359 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 360 ]</font></center> 361 <hr size="2" noshade> 362 <div class="NAVHEADER"> 363 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 364 <tr class="nav"> 365 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/renice.html" accesskey="P"><<< 366 Previous</a></td> 367 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 368 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/rmdel.html" accesskey="N">Next 369 >>></a></td> 370 </tr> 371 </table> 372 <hr align="left" width="100%"></div> 373 </body> 374 </html>