rm

Remove files (POSIX)

Syntax:

rm [-Rfir] [-d] [-l n] [-v] file...

Runs on:

QNX Neutrino, Microsoft Windows

Options:

-d
(QNX Neutrino extension) If the -R option is specified, remove the files but leave the directory tree intact (i.e. no rmdir is performed).
-f
Use force:
  • Remove each specified file without prompting for confirmation.
  • Don't write diagnostic messages or modify the exit status in the case of nonexistent operands.

If the POSIX_STRICT environment variable is defined, the utility ignores any previously specified -i options. See the note below.

In QNX Neutrino 6.6 or later, if you run rm -f without specifying any paths, the utility exits with a status of 0 and doesn't complain about the lack of arguments. This is in keeping with other implementations of rm and has been adopted by POSIX.

-i
Be interactive; request confirmation before removing each existing file.

If POSIX_STRICT is defined, the utility ignores any previously specified -f options. See the note below.

-l n
(“el”; QNX Neutrino extension) If the -R option is specified, recurse only n levels down a directory tree.
-R
Recursively remove files and subdirectories under directories given as arguments. This process removes the directory and the entire file tree under it.
CAUTION:
Use the -R option with care, as it removes directories, subdirectories, and files. Using the -i option with -R adds a measure of safety by turning on interactive prompting before each file or directory is removed.
-r
Equivalent to the -R option.
-v
(QNX Neutrino extension) Be verbose; print files and directories as they're removed.
file
The pathname of a file to be removed.

Description:

The rm utility removes each specified file from a directory.

By default, rm refuses to remove any file that names a directory. This may be overridden with the -R or -r options. In any case, rm always refuses to remove the current working directory.

If a file operand has been specified but doesn't exist and the -f option hasn't been given, a message is written to the standard error output. If -f has been given, the error message isn't written. In either case, rm goes on to any remaining files specified on the command line.

The rm utility doesn't necessarily remove the file itself. A file may have more than one link; that is, it may be known by more than one name in the filesystem (see the ln utility for information on creating links). The rm utility breaks one such link; it dissociates the file from one name. If this is the only link, the file data becomes inaccessible and the file space is returned to the system for reuse. Otherwise, the data remains accessible via other names.

Note: Currently, if POSIX_STRICT is set, -f and -i are operationally exclusive: the utility ignores all but the last instance of -i or -f. For example, rm -i -f * uses force mode, while rm -f -i * uses interactive. If POSIX_STRICT isn't set, -i makes rm use interactive mode, whether or not you specified -f.

In a future release, rm's default behavior will be changed to the POSIX behavior. To be sure that scripts, etc. work correctly with both current and later versions, either run rm with POSIX_STRICT set, or don't use -f and -i together.

Examples:

Remove the a.out and core files:

rm a.out core

Remove the directory junk and all its contents, without prompting:

rm -Rf junk

Exit status:

0
All the named files were removed.
>0
An error occurred.