rm removes each given file. By default, it does not remove directories. Synopsis:
rm [option]... [file]...
If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted.
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not affirmative, the file is skipped.
Any attempt to remove a file whose last file name component is . or .. is rejected without any prompting.
Warning: If you use rm to remove a file, it is usually possible to recover the contents of that file. If you want more assurance that the contents are truly unrecoverable, consider using shred.
The program accepts the following options. Also see Common options.
This option is useful when removing a build “chroot” hierarchy, which normally contains no valuable data. However, it is not uncommon to bind-mount /home into such a hierarchy, to make it easier to use one's start-up file. The catch is that it's easy to forget to unmount /home. Then, when you use rm -rf to remove your normally throw-away chroot, that command will remove everything under /home, too. Use the --one-file-system option, and it will warn about and skip directories on other file systems. Of course, this will not save your /home if it and your chroot happen to be on the same file system.
One common question is how to remove files whose names begin with a
‘-’. gnu rm, like every program that uses the getopt
function to parse its arguments, lets you use the ‘--’ option to
indicate that all following arguments are non-options. To remove a file
called -f in the current directory, you could type either:
rm -- -f
or:
rm ./-f
The Unix rm program's use of a single ‘-’ for this purpose predates the development of the getopt standard syntax.
An exit status of zero indicates success, and a nonzero value indicates failure.