1RM(1P)                     POSIX Programmer's Manual                    RM(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       rm — remove directory entries
14

SYNOPSIS

16       rm [−fiRr] file...
17

DESCRIPTION

19       The rm utility shall remove the directory entry specified by each  file
20       argument.
21
22       If  either  of  the  files dot or dot-dot are specified as the basename
23       portion of an operand (that is, the final pathname component) or if  an
24       operand  resolves  to  the  root directory, rm shall write a diagnostic
25       message to standard error and do nothing more with such operands.
26
27       For each file the following steps shall be taken:
28
29        1. If the file does not exist:
30
31            a. If the −f option is not specified, rm shall write a  diagnostic
32               message to standard error.
33
34            b. Go on to any remaining files.
35
36        2. If file is of type directory, the following steps shall be taken:
37
38            a. If  neither  the  −R  option nor the −r option is specified, rm
39               shall write a diagnostic message to standard error, do  nothing
40               more with file, and go on to any remaining files.
41
42            b. If  the  −f option is not specified, and either the permissions
43               of file do not permit writing and the standard input is a  ter‐
44               minal or the −i option is specified, rm shall write a prompt to
45               standard error and read a line from the standard input. If  the
46               response  is not affirmative, rm shall do nothing more with the
47               current file and go on to any remaining files.
48
49            c. For each entry contained in file, other than  dot  or  dot-dot,
50               the  four  steps  listed  here (1 to 4) shall be taken with the
51               entry as if it were a file operand. The rm  utility  shall  not
52               traverse  directories  by  following  symbolic links into other
53               parts of the hierarchy, but shall remove the links themselves.
54
55            d. If the −i option is specified, rm shall write a prompt to stan‐
56               dard  error  and  read  a  line from the standard input. If the
57               response is not affirmative, rm shall do nothing more with  the
58               current file, and go on to any remaining files.
59
60        3. If  file  is not of type directory, the −f option is not specified,
61           and either the permissions of file do not permit  writing  and  the
62           standard  input  is  a  terminal  or the −i option is specified, rm
63           shall write a prompt to the standard error and read a line from the
64           standard  input.  If  the  response is not affirmative, rm shall do
65           nothing more with the current file  and  go  on  to  any  remaining
66           files.
67
68        4. If the current file is a directory, rm shall perform actions equiv‐
69           alent to the rmdir() function defined in the System Interfaces vol‐
70           ume of POSIX.1‐2008 called with a pathname of the current file used
71           as the path argument. If the current file is not  a  directory,  rm
72           shall  perform  actions equivalent to the unlink() function defined
73           in the System Interfaces volume of POSIX.1‐2008 called with a path‐
74           name of the current file used as the path argument.
75
76           If  this  fails for any reason, rm shall write a diagnostic message
77           to standard error, do nothing more with the current file, and go on
78           to any remaining files.
79
80       The  rm  utility shall be able to descend to arbitrary depths in a file
81       hierarchy, and shall not fail due to path length limitations (unless an
82       operand specified by the user exceeds system limitations).
83

OPTIONS

85       The  rm  utility  shall  conform  to  the  Base  Definitions  volume of
86       POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.
87
88       The following options shall be supported:
89
90       −f        Do not prompt for confirmation. Do not write diagnostic  mes‐
91                 sages  or  modify  the exit status in the case of nonexistent
92                 operands. Any previous occurrences of the −i option shall  be
93                 ignored.
94
95       −i        Prompt for confirmation as described previously. Any previous
96                 occurrences of the −f option shall be ignored.
97
98       −R        Remove file hierarchies. See the DESCRIPTION.
99
100       −r        Equivalent to −R.
101

OPERANDS

103       The following operand shall be supported:
104
105       file      A pathname of a directory entry to be removed.
106

STDIN

108       The standard input shall be used to read an input line in  response  to
109       each  prompt  specified  in the STDOUT section. Otherwise, the standard
110       input shall not be used.
111

INPUT FILES

113       None.
114

ENVIRONMENT VARIABLES

116       The following environment variables shall affect the execution of rm:
117
118       LANG      Provide a default value for  the  internationalization  vari‐
119                 ables  that are unset or null. (See the Base Definitions vol‐
120                 ume of POSIX.1‐2008, Section 8.2, Internationalization  Vari‐
121                 ables  for  the  precedence of internationalization variables
122                 used to determine the values of locale categories.)
123
124       LC_ALL    If set to a non-empty string value, override  the  values  of
125                 all the other internationalization variables.
126
127       LC_COLLATE
128                 Determine  the locale for the behavior of ranges, equivalence
129                 classes, and multi-character collating elements used  in  the
130                 extended  regular  expression  defined for the yesexpr locale
131                 keyword in the LC_MESSAGES category.
132
133       LC_CTYPE  Determine the locale for the interpretation of  sequences  of
134                 bytes of text data as characters (for example, single-byte as
135                 opposed to multi-byte characters in arguments) and the behav‐
136                 ior  of  character classes within regular expressions used in
137                 the extended  regular  expression  defined  for  the  yesexpr
138                 locale keyword in the LC_MESSAGES category.
139
140       LC_MESSAGES
141                 Determine  the  locale used to process affirmative responses,
142                 and the locale used to affect  the  format  and  contents  of
143                 diagnostic messages and prompts written to standard error.
144
145       NLSPATH   Determine the location of message catalogs for the processing
146                 of LC_MESSAGES.
147

ASYNCHRONOUS EVENTS

149       Default.
150

STDOUT

152       Not used.
153

STDERR

155       Prompts shall be written to standard error under the conditions  speci‐
156       fied in the DESCRIPTION and OPTIONS sections. The prompts shall contain
157       the file pathname, but their format is otherwise unspecified. The stan‐
158       dard error also shall be used for diagnostic messages.
159

OUTPUT FILES

161       None.
162

EXTENDED DESCRIPTION

164       None.
165

EXIT STATUS

167       The following exit values shall be returned:
168
169        0    Each directory entry was successfully removed, unless its removal
170             was canceled by a non-affirmative response to a prompt  for  con‐
171             firmation.
172
173       >0    An error occurred.
174

CONSEQUENCES OF ERRORS

176       Default.
177
178       The following sections are informative.
179

APPLICATION USAGE

181       The  rm  utility  is  forbidden  to remove the names dot and dot-dot in
182       order to avoid the consequences of inadvertently doing something like:
183
184           rm −r .*
185
186       Some implementations do not permit the removal of the last link  to  an
187       executable binary file that is being executed; see the [EBUSY] error in
188       the unlink() function  defined  in  the  System  Interfaces  volume  of
189       POSIX.1‐2008. Thus, the rm utility can fail to remove such files.
190
191       The  −i  option causes rm to prompt and read the standard input even if
192       the standard input is not a terminal, but in the absence of −i the mode
193       prompting is not done when the standard input is not a terminal.
194

EXAMPLES

196        1. The following command:
197
198               rm a.out core
199
200           removes the directory entries: a.out and core.
201
202        2. The following command:
203
204               rm −Rf junk
205
206           removes the directory junk and all its contents, without prompting.
207

RATIONALE

209       For  absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of rm
210       describing the behavior when  prompting  for  confirmation,  should  be
211       interpreted in the following manner:
212
213           if ((NOT f_option) AND
214               ((not_writable AND input_is_terminal) OR i_option))
215
216       The  exact  format  of the interactive prompts is unspecified. Only the
217       general nature of the contents of prompts are specified because  imple‐
218       mentations  may desire more descriptive prompts than those used on his‐
219       torical implementations. Therefore, an application  not  using  the  −f
220       option,  or  using  the  −i option, relies on the system to provide the
221       most suitable dialog directly with the  user,  based  on  the  behavior
222       specified.
223
224       The  −r option is historical practice on all known systems. The synonym
225       −R option is provided for consistency with the other utilities in  this
226       volume  of  POSIX.1‐2008  that  provide  options  requesting  recursive
227       descent through the file hierarchy.
228
229       The behavior of the −f option in historical versions of rm is inconsis‐
230       tent.  In  general, along with ``forcing'' the unlink without prompting
231       for permission, it always causes diagnostic messages to  be  suppressed
232       and the exit status to be unmodified for nonexistent operands and files
233       that cannot be unlinked. In some versions, however, the −f option  sup‐
234       presses  usage  messages  and  system errors as well.  Suppressing such
235       messages is not a service to either shell scripts or users.
236
237       It is less clear that error messages regarding  files  that  cannot  be
238       unlinked  (removed)  should  be suppressed. Although this is historical
239       practice, this volume of POSIX.1‐2008 does not permit the −f option  to
240       suppress such messages.
241
242       When  given the −r and −i options, historical versions of rm prompt the
243       user twice for each directory, once before removing  its  contents  and
244       once  before  actually  attempting  to  delete the directory entry that
245       names it. This allows the user to ``prune'' the  file  hierarchy  walk.
246       Historical versions of rm were inconsistent in that some did not do the
247       former prompt for directories named on the command line and others  had
248       obscure  prompting  behavior  when  the −i option was specified and the
249       permissions of the file did not permit writing.  The  POSIX  Shell  and
250       Utilities  rm  differs  little from historic practice, but does require
251       that prompts be consistent. Historical versions of rm were also  incon‐
252       sistent  in that prompts were done to both standard output and standard
253       error. This volume of POSIX.1‐2008 requires that  prompts  be  done  to
254       standard error, for consistency with cp and mv, and to allow historical
255       extensions to rm that provide an option to list deleted files on  stan‐
256       dard output.
257
258       The  rm  utility is required to descend to arbitrary depths so that any
259       file hierarchy may be deleted. This means, for  example,  that  the  rm
260       utility cannot run out of file descriptors during its descent (that is,
261       if the number of file descriptors is limited, rm cannot be  implemented
262       in  the historical fashion where one file descriptor is used per direc‐
263       tory level). Also, rm is not permitted to fail because of  path  length
264       restrictions,  unless  an  operand specified by the user is longer than
265       {PATH_MAX}.
266
267       The rm utility removes symbolic links themselves, not  the  files  they
268       refer  to, as a consequence of the dependence on the unlink() function‐
269       ality, per the DESCRIPTION. When removing hierarchies with  −r  or  −R,
270       the prohibition on following symbolic links has to be made explicit.
271

FUTURE DIRECTIONS

273       None.
274

SEE ALSO

276       rmdir
277
278       The  Base  Definitions  volume  of POSIX.1‐2008, Chapter 8, Environment
279       Variables, Section 12.2, Utility Syntax Guidelines
280
281       The  System  Interfaces  volume  of  POSIX.1‐2008,  remove(),  rmdir(),
282       unlink()
283
285       Portions  of  this text are reprinted and reproduced in electronic form
286       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
287       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
288       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
289       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
290       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
291       event of any discrepancy between this version and the original IEEE and
292       The Open Group Standard, the original IEEE and The Open Group  Standard
293       is  the  referee document. The original Standard can be obtained online
294       at http://www.unix.org/online.html .
295
296       Any typographical or formatting errors that appear  in  this  page  are
297       most likely to have been introduced during the conversion of the source
298       files to man page format. To report such errors,  see  https://www.ker
299       nel.org/doc/man-pages/reporting_bugs.html .
300
301
302
303IEEE/The Open Group                  2013                               RM(1P)
Impressum