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