UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 23.9 delete: Protecting Files from Accidental Deletion Chapter 23
Removing Files
Next: 23.11 Deleting Files with Odd Names
 

23.10 Deletion with Prejudice: rm -f

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?

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]

- ML


Previous: 23.9 delete: Protecting Files from Accidental Deletion UNIX Power ToolsNext: 23.11 Deleting Files with Odd Names
23.9 delete: Protecting Files from Accidental Deletion Book Index23.11 Deleting Files with Odd Names

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System