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

NAME

12       rm - remove directory entries
13

SYNOPSIS

15       rm [-fiRr] file...
16

DESCRIPTION

18       The rm utility shall remove the directory entry specified by each  file
19       argument.
20
21       If  either  of  the  files dot or dot-dot are specified as the basename
22       portion of an operand (that is, the final pathname component), rm shall
23       write  a  diagnostic message to standard error and do nothing more with
24       such operands.
25
26       For each file the following steps shall be taken:
27
28        1. If the file does not exist:
29
30            a. If the -f option is not specified, rm shall write a  diagnostic
31               message to standard error.
32
33            b. Go on to any remaining files.
34
35        2. If file is of type directory, the following steps shall be taken:
36
37            a. If  neither  the  -R  option nor the -r option is specified, rm
38               shall write a diagnostic message to standard error, do  nothing
39               more with file, and go on to any remaining files.
40
41            b. If  the  -f option is not specified, and either the permissions
42               of file do not permit writing and the standard input is a  ter‐
43               minal or the -i option is specified, rm shall write a prompt to
44               standard error and read a line from the standard input. If  the
45               response  is not affirmative, rm shall do nothing more with the
46               current file and go on to any remaining files.
47
48            c. For each entry contained in file, other than  dot  or  dot-dot,
49               the  four  steps  listed  here (1 to 4) shall be taken with the
50               entry as if it were a file operand. The rm  utility  shall  not
51               traverse  directories  by  following  symbolic links into other
52               parts of the hierarchy, but shall remove the links themselves.
53
54            d. If the -i option is specified, rm shall write a prompt to stan‐
55               dard  error  and  read  a line from the standard input.  If the
56               response is not affirmative, rm shall do nothing more with  the
57               current file, and go on to any remaining files.
58
59        3. If  file  is not of type directory, the -f option is not specified,
60           and either the permissions of file do not permit  writing  and  the
61           standard  input  is  a  terminal  or the -i option is specified, rm
62           shall write a prompt to the standard error and read a line from the
63           standard  input.  If  the  response is not affirmative, rm shall do
64           nothing more with the current file  and  go  on  to  any  remaining
65           files.
66
67        4. If the current file is a directory, rm shall perform actions equiv‐
68           alent to the rmdir() function defined in the System Interfaces vol‐
69           ume  of  IEEE Std 1003.1-2001 called with a pathname of the current
70           file used as the path argument. If the current file is not a direc‐
71           tory,  rm shall perform actions equivalent to the unlink() function
72           defined in the System  Interfaces  volume  of  IEEE Std 1003.1-2001
73           called  with  a pathname of the current file used as the path argu‐
74           ment.
75
76       If this fails for any reason, rm shall write a  diagnostic  message  to
77       standard error, do nothing more with the current file, and go on to any
78       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       IEEE Std 1003.1-2001, 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 messages
91              or modify the exit status in the case of  nonexistent  operands.
92              Any previous occurrences of the -i option shall be ignored.
93
94       -i     Prompt  for  confirmation  as described previously. Any previous
95              occurrences of the -f option shall be ignored.
96
97       -R     Remove file hierarchies. See the DESCRIPTION.
98
99       -r     Equivalent to -R.
100
101

OPERANDS

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

STDIN

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

INPUT FILES

114       None.
115

ENVIRONMENT VARIABLES

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

ASYNCHRONOUS EVENTS

154       Default.
155

STDOUT

157       Not used.
158

STDERR

160       Prompts shall be written to standard error under the conditions  speci‐
161       fied in the DESCRIPTION and OPTIONS sections. The prompts shall contain
162       the file pathname, but their format is otherwise unspecified. The stan‐
163       dard error also shall be used for diagnostic messages.
164

OUTPUT FILES

166       None.
167

EXTENDED DESCRIPTION

169       None.
170

EXIT STATUS

172       The following exit values shall be returned:
173
174        0     All  of  the  named  directory  entries  for  which rm performed
175              actions equivalent to the rmdir()  or  unlink()  functions  were
176              removed.
177
178       >0     An error occurred.
179
180

CONSEQUENCES OF ERRORS

182       Default.
183
184       The following sections are informative.
185

APPLICATION USAGE

187       The  rm  utility  is  forbidden  to remove the names dot and dot-dot in
188       order to avoid the consequences of inadvertently doing something like:
189
190
191              rm -r .*
192
193       Some implementations do not permit the removal of the last link  to  an
194       executable binary file that is being executed; see the [EBUSY] error in
195       the unlink() function  defined  in  the  System  Interfaces  volume  of
196       IEEE Std 1003.1-2001.  Thus,  the  rm  utility  can fail to remove such
197       files.
198
199       The -i option causes rm to prompt and read the standard input  even  if
200       the standard input is not a terminal, but in the absence of -i the mode
201       prompting is not done when the standard input is not a terminal.
202

EXAMPLES

204        1. The following command:
205
206
207           rm a.out core
208
209       removes the directory entries: a.out and core.
210
211        2. The following command:
212
213
214           rm -Rf junk
215
216       removes the directory junk and all its contents, without prompting.
217

RATIONALE

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

FUTURE DIRECTIONS

284       None.
285

SEE ALSO

287       rmdir(),  the  System  Interfaces   volume   of   IEEE Std 1003.1-2001,
288       remove(), rmdir(), unlink()
289
291       Portions  of  this text are reprinted and reproduced in electronic form
292       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
293       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
294       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
295       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
296       event of any discrepancy between this version and the original IEEE and
297       The  Open Group Standard, the original IEEE and The Open Group Standard
298       is the referee document. The original Standard can be  obtained  online
299       at http://www.opengroup.org/unix/online.html .
300
301
302
303IEEE/The Open Group                  2003                               RM(1P)
Impressum