RM(1P)
๐ธ RM(1P) โ the POSIX Programmer's Manual, bestie edition ๐ธ
POSIX Programmer's Manual ยท RM(1P)
๐ซ PROLOG (read this first, it's important)
Okay so this manual page is part of the POSIX Programmer's Manual. Heads up tho: the Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all. ๐
โจ NAME
rm โ remove directory entries ๐
๐ SYNOPSIS
rm [-iRr] file...
rm -f [-iRr] [file...]
๐ฆ DESCRIPTION
So the rm utility shall remove the directory entry specified by each file argument. That's the whole vibe. Poof. Gone. โจ
Now, if either of the files dot or dot-dot are specified as the basename portion of an operand (that means the final pathname component, bestie), or if an operand resolves to the root directory, rm shall write a diagnostic message to standard error and do nothing more with such operands. It's giving "absolutely not." ๐
For each file the following steps shall be taken:
- If the file does not exist:
- a. If the
-foption is not specified,rmshall write a diagnostic message to standard error. - b. Go on to any remaining files.
- a. If the
- If file is of type directory, the following steps shall be taken:
- a. If neither the
-Roption nor the-roption is specified,rmshall write a diagnostic message to standard error, do nothing more with file, and go on to any remaining files. - b. If file is an empty directory,
rmmay skip to step 2d. If the-foption is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the-ioption is specified,rmshall write a prompt to standard error and read a line from the standard input. If the response is not affirmative,rmshall do nothing more with the current file and go on to any remaining files. - c. For each entry contained in file, other than
dotordot-dot, the four steps listed here (1 to 4) shall be taken with the entry as if it were a file operand. Thermutility shall not traverse directories by following symbolic links into other parts of the hierarchy, but shall remove the links themselves. ๐ซ๐ - d. If the
-ioption is specified,rmshall write a prompt to standard error and read a line from the standard input. If the response is not affirmative,rmshall do nothing more with the current file, and go on to any remaining files.
- a. If neither the
- If file is not of type directory, the
-foption is not specified, and either the permissions of file do not permit writing and the standard input is a terminal or the-ioption is specified,rmshall write a prompt to the standard error and read a line from the standard input. If the response is not affirmative,rmshall do nothing more with the current file and go on to any remaining files. - If the current file is a directory,
rmshall perform actions equivalent to thermdir()function defined in the System Interfaces volume of POSIX.1โ2017 called with a pathname of the current file used as the path argument. If the current file is not a directory,rmshall perform actions equivalent to theunlink()function defined in the System Interfaces volume of POSIX.1โ2017 called with a pathname of the current file used as the path argument.
If this fails for any reason, rm shall write a diagnostic message to standard error, do nothing more with the current file, and go on to any remaining files.
The rm utility shall be able to descend to arbitrary depths in a file hierarchy, and shall not fail due to path length limitations (unless an operand specified by the user exceeds system limitations). No depth is too deep for her, periodt. ๐ณ๏ธ๐
๐ OPTIONS
The rm utility shall conform to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines.
The following options shall be supported:
-fโ Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of no file operands, or in the case of operands that do not exist. Any previous occurrences of the-ioption shall be ignored. It's the "no thoughts, just delete" mode. ๐-iโ Prompt for confirmation as described previously. Any previous occurrences of the-foption shall be ignored. The responsible queen. ๐-Rโ Remove file hierarchies. See the DESCRIPTION.-rโ Equivalent to-R. Same energy, different letter, we love a twin moment. ๐ซถ
๐ OPERANDS
The following operand shall be supported:
- file โ A pathname of a directory entry to be removed.
๐ STDIN
The standard input shall be used to read an input line in response to each prompt specified in the STDOUT section. Otherwise, the standard input shall not be used. (Yes bestie, it says STDOUT, that's literally what the original says, we don't question the ancestors.) ๐
๐ง INPUT FILES
None.
๐ ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of rm:
LANGโ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLโ If set to a non-empty string value, override the values of all the other internationalization variables. Main character, overrides everyone. ๐LC_COLLATEโ Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the extended regular expression defined for theyesexprlocale keyword in theLC_MESSAGEScategory.LC_CTYPEโ Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments) and the behavior of character classes within regular expressions used in the extended regular expression defined for theyesexprlocale keyword in theLC_MESSAGEScategory.LC_MESSAGESโ Determine the locale used to process affirmative responses, and the locale used to affect the format and contents of diagnostic messages and prompts written to standard error.NLSPATHโ Determine the location of message catalogs for the processing ofLC_MESSAGES.
โก ASYNCHRONOUS EVENTS
Default.
๐ธ STDOUT
Not used. She's not here to chat, she's here to delete. ๐ซฅ
๐ STDERR
Prompts shall be written to standard error under the conditions specified in the DESCRIPTION and OPTIONS sections. The prompts shall contain the file pathname, but their format is otherwise unspecified. The standard error also shall be used for diagnostic messages.
๐ฆ OUTPUT FILES
None.
โญ EXTENDED DESCRIPTION
None.
๐ฅ EXIT STATUS
The following exit values shall be returned:
0โ Each directory entry was successfully removed, unless its removal was canceled by a non-affirmative response to a prompt for confirmation.>0โ An error occurred. ๐ญ
๐ CONSEQUENCES OF ERRORS
Default.
The following sections are informative.
๐ APPLICATION USAGE
The rm utility is forbidden to remove the names dot and dot-dot in order to avoid the consequences of inadvertently doing something like:
rm -r .*
Some implementations do not permit the removal of the last link to an executable binary file that is being executed; see the [EBUSY] error in the unlink() function defined in the System Interfaces volume of POSIX.1โ2017. Thus, the rm utility can fail to remove such files. Not a skill issue, just POSIX being POSIX. ๐
The -i option causes rm to prompt and read the standard input even if the standard input is not a terminal, but in the absence of -i the mode prompting is not done when the standard input is not a terminal.
๐ EXAMPLES
- The following command:
rm a.out core
removes the directory entries: a.out and core.
- The following command:
rm -Rf junk
removes the directory junk and all its contents, without prompting. No cap, it just goes. ๐ฅ
โจ RATIONALE โจ
ok bestie, listen up, because this part is where the standard is basically like "let me explain myself" ๐
For absolute clarity, paragraphs (2b) and (3) in the DESCRIPTION of rm (the ones about what happens when it's prompting you for confirmation) should be read like this:
if ((NOT f_option) AND
((not_writable AND input_is_terminal) OR i_option))
The exact format of the interactive prompts is unspecified ๐. Only the general nature of what's in the prompts is specified, because implementations might want to write prompts that are way more descriptive than the ones the historical implementations used. So basically: if an application isn't using the -f option, or is using the -i option, it's relying on the system to serve up the most suitable dialog directly with the user, based on the behavior that's specified. no cap.
The -r option is historical practice on all known systems ๐ซถ. The synonym -R option is provided for consistency with the other utilities in this volume of POSIX.1โ2017 that offer options requesting recursive descent through the file hierarchy.
The behavior of the -f option in historical versions of rm is inconsistent ๐ญ. In general, along with "forcing" the unlink without prompting for permission, it always causes diagnostic messages to be suppressed and the exit status to be unmodified for nonexistent operands and files that cannot be unlinked. In some versions, though, the -f option suppresses usage messages and system errors as well. And suppressing such messages is not a service to either shell scripts or users, fr fr.
It's less clear that error messages regarding files that cannot be unlinked (removed) should be suppressed. Even though that's historical practice, this volume of POSIX.1โ2017 does not permit the -f option to suppress such messages. periodt.
When given the -r and -i options, historical versions of rm prompt the user twice for each directory โ once before removing its contents and once before actually attempting to delete the directory entry that names it. This lets the user "prune" the file hierarchy walk ๐ธ. Historical versions of rm were inconsistent in that some did not do the former prompt for directories named on the command line, and others had obscure prompting behavior when the -i option was specified and the permissions of the file did not permit writing. The POSIX Shell and Utilities rm differs little from historic practice, but it does require that prompts be consistent. Historical versions of rm were also inconsistent in that prompts were done to both standard output and standard error. This volume of POSIX.1โ2017 requires that prompts be done to standard error, for consistency with cp and mv, and to allow historical extensions to rm that provide an option to list deleted files on standard output. iconic behavior tbh.
The rm utility is required to descend to arbitrary depths so that any file hierarchy may be deleted ๐ณ๏ธ. This means, for example, that the rm utility cannot run out of file descriptors during its descent (that is, if the number of file descriptors is limited, rm cannot be implemented in the historical fashion where one file descriptor is used per directory level). Also, rm is not permitted to fail because of path length restrictions, unless an operand specified by the user is longer than {PATH_MAX}.
The rm utility removes symbolic links themselves, not the files they refer to, as a consequence of the dependence on the unlink() functionality, per the DESCRIPTION. When removing hierarchies with -r or -R, the prohibition on following symbolic links has to be made explicit ๐ฅ.
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
like... nothing. the future is empty. she said what she said ๐
๐ SEE ALSO ๐
rmdir- The Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
- The System Interfaces volume of POSIX.1โ2017,
remove(),rmdir(),unlink()
๐ COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version 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 .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie ๐ this one came from the IEEE/The Open Group, dated 2017, and it signs off as RM(1P). go forth and delete responsibly, mwah ๐ซถโจ
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms