1 '\" te
   2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
   3 .\" Copyright 1989 AT&T
   4 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
   5 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
   6 .\" Copyright 2014 Andrew Stormont.
   7 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   8 .\" http://www.opengroup.org/bookstore/.
   9 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
  10 .\"  This notice shall appear on any product containing this material.
  11 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
  12 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
  13 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  14 .TH RM 1 "Apr 30, 2014"
  15 .SH NAME
  16 rm, rmdir \- remove directory entries
  17 .SH SYNOPSIS
  18 .LP
  19 .nf
  20 \fB/usr/bin/rm\fR [\fB-f\fR] [\fB-i\fR] [\fB-v\fR] \fIfile\fR...
  21 .fi
  22 
  23 .LP
  24 .nf
  25 \fB/usr/bin/rm\fR \fB-rR\fR [\fB-f\fR] [\fB-i\fR] [\fB-v\fR] \fIdirname\fR... [\fIfile\fR]...
  26 .fi
  27 
  28 .LP
  29 .nf
  30 \fB/usr/bin/rmdir\fR [\fB-ps\fR] \fIdirname\fR...
  31 .fi
  32 
  33 .SS "ksh93"
  34 .LP
  35 .nf
  36 \fB/usr/bin/rmdir\fR [\fB-eps\fR] \fIdirname\fR...
  37 .fi
  38 
  39 .SH DESCRIPTION
  40 .SS "/usr/bin/rm"
  41 .sp
  42 .LP
  43 The \fBrm\fR utility removes the directory entry specified by each \fIfile\fR
  44 argument. If a file has no write permission and the standard input is a
  45 terminal, the full set of permissions (in octal) for the file are printed
  46 followed by a question mark. This is a prompt for confirmation. If the answer
  47 is affirmative, the file is deleted, otherwise the file remains.
  48 .sp
  49 .LP
  50 If \fIfile\fR is a symbolic link, the link is removed, but the file or
  51 directory to which it refers is not deleted. Users do not need write permission
  52 to remove a symbolic link, provided they have write permissions in the
  53 directory.
  54 .sp
  55 .LP
  56 If multiple \fIfile\fRs are specified and removal of a \fIfile\fR fails for any
  57 reason, \fBrm\fR writes a diagnostic message to standard error, do nothing more
  58 to the current \fIfile\fR, and go on to any remaining \fIfile\fRs.
  59 .sp
  60 .LP
  61 If the standard input is not a terminal, the utility operates as if the
  62 \fB-f\fR option is in effect.
  63 .SS "/usr/bin/rmdir"
  64 .sp
  65 .LP
  66 The \fBrmdir\fR utility removes the directory entry specified by each
  67 \fIdirname\fR operand, which must refer to an empty directory.
  68 .sp
  69 .LP
  70 Directories are processed in the order specified. If a directory and a
  71 subdirectory of that directory are specified in a single invocation of
  72 \fBrmdir\fR, the subdirectory must be specified before the parent directory so
  73 that the parent directory is empty when \fBrmdir\fR tries to remove it.
  74 .SS "ksh93"
  75 .sp
  76 .LP
  77 The \fBrmdir\fR built-in in \fBksh93\fR is associated with the \fB/bin\fR and
  78 \fB/usr/bin\fR paths. It is invoked when \fBrmdir\fR is executed without a
  79 pathname prefix and the pathname search finds a \fB/bin/rmdir\fR or
  80 \fB/usr/bin/rmdir\fR executable.
  81 .sp
  82 .LP
  83 \fBrmdir\fR deletes each given directory. The directory must be empty and
  84 contain no entries other than \fB\&.\fR or \fB\&..\fR. If a directory and a
  85 subdirectory of that directory are specified as operands, the subdirectory must
  86 be specified before the parent, so that the parent directory is empty when
  87 \fBrmdir\fR attempts to remove it.
  88 .SH OPTIONS
  89 .sp
  90 .LP
  91 The following options are supported for \fB/usr/bin/rm\fR only:
  92 .sp
  93 .ne 2
  94 .na
  95 \fB\fB-r\fR\fR
  96 .ad
  97 .RS 6n
  98 Recursively removes directories and subdirectories in the argument list. The
  99 directory is emptied of files and removed. The user is normally prompted for
 100 removal of any write-protected files which the directory contains. The
 101 write-protected files are removed without prompting, however, if the \fB-f\fR
 102 option is used, or if the standard input is not a terminal and the \fB-i\fR
 103 option is not used.
 104 .sp
 105 Symbolic links that are encountered with this option is not traversed.
 106 .sp
 107 If the removal of a non-empty, write-protected directory is attempted, the
 108 utility always fails (even if the \fB-f\fR option is used), resulting in an
 109 error message.
 110 .RE
 111 
 112 .sp
 113 .ne 2
 114 .na
 115 \fB\fB-R\fR\fR
 116 .ad
 117 .RS 6n
 118 Same as \fB-r\fR option.
 119 .RE
 120 
 121 .sp
 122 .ne 2
 123 .na
 124 \fB\fB-v\fR\fR
 125 .ad
 126 .RS 6n
 127 Print out the name of files and directories removed.
 128 .RE
 129 
 130 .SS "/usr/bin/rm"
 131 .sp
 132 .LP
 133 The following options are supported for \fB/usr/bin/rm\fR only:
 134 .sp
 135 .ne 2
 136 .na
 137 \fB\fB-f\fR\fR
 138 .ad
 139 .RS 6n
 140 Removes all files (whether write-protected or not) in a directory without
 141 prompting the user.
 142 .RE
 143 
 144 .sp
 145 .ne 2
 146 .na
 147 \fB\fB-i\fR\fR
 148 .ad
 149 .RS 6n
 150 Interactive. With this option, \fBrm\fR prompts for confirmation before
 151 removing any files. It overrides the \fB-f\fR option and remains in effect even
 152 if the standard input is not a terminal.
 153 .RE
 154 
 155 .SS "/usr/bin/rmdir"
 156 .sp
 157 .LP
 158 The following options are supported for \fB/usr/bin/rmdir\fR only:
 159 .sp
 160 .ne 2
 161 .na
 162 \fB\fB-p\fR\fR
 163 .ad
 164 .RS 6n
 165 Allows users to remove the directory \fIdirname\fR and its parent directories
 166 which become empty. A message is printed to standard error if all or part of
 167 the path could not be removed.
 168 .RE
 169 
 170 .sp
 171 .ne 2
 172 .na
 173 \fB\fB-s\fR\fR
 174 .ad
 175 .RS 6n
 176 Suppresses the message printed on the standard error when \fB-p\fR is in
 177 effect.
 178 .RE
 179 
 180 .SS "ksh93"
 181 .sp
 182 .LP
 183 The following options are supported for the \fBrmdir\fR built-in for
 184 \fBksh93\fR:
 185 .sp
 186 .ne 2
 187 .na
 188 \fB\fB-e\fR\fR
 189 .ad
 190 .br
 191 .na
 192 \fB\fB--ignore-fail-on-non-empty\fR\fR
 193 .ad
 194 .RS 30n
 195 Ignore each non-empty directory failure.
 196 .RE
 197 
 198 .sp
 199 .ne 2
 200 .na
 201 \fB\fB-p\fR\fR
 202 .ad
 203 .br
 204 .na
 205 \fB\fB--parents\fR\fR
 206 .ad
 207 .RS 30n
 208 Remove each explicit directory argument directory that becomes empty after its
 209 child directories are removed.
 210 .RE
 211 
 212 .sp
 213 .ne 2
 214 .na
 215 \fB\fB-s\fR\fR
 216 .ad
 217 .br
 218 .na
 219 \fB\fB--suppress\fR\fR
 220 .ad
 221 .RS 30n
 222 Suppress the message printed on the standard error when \fB-p\fR is in effect.
 223 .RE
 224 
 225 .SH OPERANDS
 226 .sp
 227 .LP
 228 The following operands are supported:
 229 .sp
 230 .ne 2
 231 .na
 232 \fB\fIfile\fR\fR
 233 .ad
 234 .RS 11n
 235 Specifies the pathname of a directory entry to be removed.
 236 .RE
 237 
 238 .sp
 239 .ne 2
 240 .na
 241 \fB\fIdirname\fR\fR
 242 .ad
 243 .RS 11n
 244 Specifies the pathname of an empty directory to be removed.
 245 .RE
 246 
 247 .SH USAGE
 248 .sp
 249 .LP
 250 See \fBlargefile\fR(5) for the description of the behavior of \fBrm\fR and
 251 \fBrmdir\fR when encountering files greater than or equal to 2 Gbyte ( 2^31
 252 bytes).
 253 .SH EXAMPLES
 254 .sp
 255 .LP
 256 The following examples are valid for the commands shown.
 257 .SS "/usr/bin/rm"
 258 .LP
 259 \fBExample 1 \fRRemoving Directories
 260 .sp
 261 .LP
 262 The following command removes the directory entries \fBa.out\fR and \fBcore\fR:
 263 
 264 .sp
 265 .in +2
 266 .nf
 267 example% \fBrm a.out core\fR
 268 .fi
 269 .in -2
 270 .sp
 271 
 272 .LP
 273 \fBExample 2 \fRRemoving a Directory without Prompting
 274 .sp
 275 .LP
 276 The following command removes the directory \fBjunk\fR and all its contents,
 277 without prompting:
 278 
 279 .sp
 280 .in +2
 281 .nf
 282 example% \fBrm -rf junk\fR
 283 .fi
 284 .in -2
 285 .sp
 286 
 287 .SS "/usr/bin/rmdir"
 288 .LP
 289 \fBExample 3 \fRRemoving Empty Directories
 290 .sp
 291 .LP
 292 If a directory \fBa\fR in the current directory is empty, except that it
 293 contains a directory \fBb\fR, and \fBa/b\fR is empty except that it contains a
 294 directory \fBc\fR, the following command removes all three directories:
 295 
 296 .sp
 297 .in +2
 298 .nf
 299 example% \fBrmdir -p a/b/c\fR
 300 .fi
 301 .in -2
 302 .sp
 303 
 304 .SH ENVIRONMENT VARIABLES
 305 .sp
 306 .LP
 307 See \fBenviron\fR(5) for descriptions of the following environment variables
 308 that affect the execution of \fBrm\fR and \fBrmdir\fR: \fBLANG\fR,
 309 \fBLC_ALL\fR, \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and
 310 \fBNLSPATH\fR.
 311 .sp
 312 .LP
 313 Affirmative responses are processed using the extended regular expression
 314 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
 315 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
 316 the behavior of ranges, equivalence classes, and multi-character collating
 317 elements used in the expression defined for \fByesexpr\fR. The locale specified
 318 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
 319 bytes of text data a characters, the behavior of character classes used in the
 320 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
 321 .SH EXIT STATUS
 322 .sp
 323 .LP
 324 The following exit values are returned:
 325 .sp
 326 .ne 2
 327 .na
 328 \fB\fB0\fR\fR
 329 .ad
 330 .RS 6n
 331 If the \fB-f\fR option was not specified, all the named directory entries were
 332 removed; otherwise, all the existing named directory entries were removed.
 333 .RE
 334 
 335 .sp
 336 .ne 2
 337 .na
 338 \fB\fB>0\fR\fR
 339 .ad
 340 .RS 6n
 341 An error occurred.
 342 .RE
 343 
 344 .SS "ksh93"
 345 .sp
 346 .LP
 347 The following exit values are returned:
 348 .sp
 349 .ne 2
 350 .na
 351 \fB\fB0\fR\fR
 352 .ad
 353 .RS 6n
 354 Successful completion. All directories deleted successfully.
 355 .RE
 356 
 357 .sp
 358 .ne 2
 359 .na
 360 \fB\fB>0\fR\fR
 361 .ad
 362 .RS 6n
 363 An error occurred. One or more directories could not be deleted.
 364 .RE
 365 
 366 .SH ATTRIBUTES
 367 .sp
 368 .LP
 369 See \fBattributes\fR(5) for descriptions of the following attributes:
 370 .SS "/usr/bin/rm, /usr/bin/rmdir"
 371 .sp
 372 
 373 .sp
 374 .TS
 375 box;
 376 c | c
 377 l | l .
 378 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 379 _
 380 CSI     Enabled
 381 .TE
 382 
 383 .SS "ksh93"
 384 .sp
 385 
 386 .sp
 387 .TS
 388 box;
 389 c | c
 390 l | l .
 391 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 392 _
 393 Interface Stability     See below.
 394 .TE
 395 
 396 .sp
 397 .LP
 398 The \fBksh93\fR built-in binding to \fB/bin\fR and \fB/usr/bin\fR is Volatile.
 399 The built-in interfaces are Uncommitted.
 400 .SH SEE ALSO
 401 .sp
 402 .LP
 403 \fBksh93\fR(1), \fBrmdir\fR(2), \fBrmdir\fR(2), \fBunlink\fR(2),
 404 \fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5)
 405 .SH DIAGNOSTICS
 406 .sp
 407 .LP
 408 All messages are generally self-explanatory.
 409 .sp
 410 .LP
 411 It is forbidden to remove the files "\fB\&.\fR" and "\fB\&..\fR" in order to
 412 avoid the consequences of inadvertently doing something like the following:
 413 .sp
 414 .in +2
 415 .nf
 416 example% \fBrm -r .*\fR
 417 .fi
 418 .in -2
 419 .sp
 420 
 421 .sp
 422 .LP
 423 It is forbidden to remove the file "\fB/\fR" in order to avoid the consequences
 424 of inadvertently doing something like:
 425 .sp
 426 .in +2
 427 .nf
 428 example% \fBrm -rf $x/$y\fR
 429 .fi
 430 .in -2
 431 .sp
 432 
 433 .sp
 434 .LP
 435 or
 436 .sp
 437 .in +2
 438 .nf
 439 example% \fBrm -rf /$y\fR
 440 .fi
 441 .in -2
 442 .sp
 443 
 444 .sp
 445 .LP
 446 when \fB$x\fR and \fB$y\fR expand to empty strings.
 447 .SH NOTES
 448 .sp
 449 .LP
 450 A \fB\(mi\fR permits the user to mark explicitly the end of any command line
 451 options, allowing \fBrm\fR to recognize file arguments that begin with a
 452 \fB\(mi\fR\&. As an aid to BSD migration, \fBrm\fR accepts \fB\(mi\|\(mi\fR as
 453 a synonym for \fB\(mi\fR\&. This migration aid may disappear in a future
 454 release. If a \fB\(mi\|\(mi\fR and a \fB\(mi\fR both appear on the same command
 455 line, the second is interpreted as a file.