The -f option to rm is the extreme opposite of -i ( 21.11 ) . It says, "Just delete the file; don't ask me any questions." The "f" stands (allegedly) for "force," but this isn't quite right. rm -f won't force the deletion of something that you aren't allowed to delete. (To understand what you're allowed to delete, you need to understand file access permissions ( 22.2 ) .)
What, then, does rm -f do, and why would you want to use it?
Normally,
rm
asks you for confirmation if you tell it to delete files to which you don't have write access - you'll get a message like
Override protection 444 for foo?
(The UNIX filesystem allows you to delete read-only files, provided you own the file and provided you have write access to the directory.) With
-f
, these files will be deleted silently.
Normally, rm 's exit status ( 44.7 ) is 0 if it succeeded and 1 if it failed to delete the file. With -f , rm 's return status is always 0.
I find that I rarely use rm -f on the UNIX command line, but I almost always use it within shell scripts. In a shell script, you (probably) don't want to be interrupted by lots of prompts should rm find a bunch of read-only files.
[You probably also don't want to be interrupted if rm -f tries to delete files that don't exist because the script never created them. In some UNIXes, rm -f will give an error here; in others, it won't. -JP ]
-