# Chapter 14. Removing Files

#### Contents:

The Cycle of Creation and Destruction
How Unix Keeps Track of Files: Inodes
rm and Its Dangers
Tricks for Making rm Safer
Answer "Yes" or "No" Forever with yes
Remove Some, Leave Some
A Faster Way to Remove Files Interactively
Safer File Deletion in Some Directories
Safe Delete: Pros and Cons
Deletion with Prejudice: rm -f
Deleting Files with Odd Names
Using Wildcards to Delete Files with Strange Names
Handling a Filename Starting with a Dash (-)
Using unlink to Remove a File with a Strange Name
Removing a Strange File by its i-number
Problems Deleting Directories
Deleting Stale Files
Removing Every File but One
Using find to Clear Out Unneeded Files

## 14.1. The Cycle of Creation and Destruction

As a computer user, you spend lots of time creating files. Just as the necessary counterpart of life is death, the other side of file creation is deletion. If you never delete any files, you soon have a computer's equivalent of a population explosion: your disks get full, and you must either spend money (buy and install more disk drives) or figure out which files you don't really need.

In this chapter, we'll talk about ways to get rid of files: how to do it safely, how to get rid of files that don't want to die, and how to find "stale" files -- or unused files that have been around for a long time. "Safe" deletion is a particularly interesting topic, because Unix's rm command is extreme: once you delete a file, it's gone permanently. There are several solutions for working around this problem, letting you (possibly) reclaim files from the dead.

-- ML

Copyright © 2003 O'Reilly & Associates. All rights reserved.