Safe File and Folder Deletion
Introduction
Nothing you've run so far has been completely risk-free. cp and mv will overwrite an existing destination file silently, with no prompt, and the file that was there is not coming back — that's exactly why Lesson 5 built the inspect-first habit. Deletion, though, is the operation whose entire purpose is to destroy something. There is no Trash folder waiting behind rm, and no dialog box asking, "Are you sure?" before a file disappears. Once you delete something from the terminal, it is simply gone.
That finality is exactly why this lesson exists. You'll learn to remove things in order of size and risk: a single file first, then an empty directory, then a directory that still has contents, and finally an entire tree of files and folders in one command. You'll also meet the interactive forms that ask you to confirm before each removal. At every step, the rule is the same — look before you remove, because looking is the only chance you get.
Inspecting the target before removing
Back in Lesson 5, you built the inspect-first habit: list what's there before you act, then list again to confirm what changed. That habit mattered for cp and mv because a wrong destination could silently overwrite a file. With deletion, the stakes are higher still — the whole point of the command is to remove data, so the listing you run before the command is your only real safety check. If a file is misspelled in your command or a path points somewhere you didn't intend, ls will tell you before it's too late to matter.
Let's build a small workspace to practice in, right inside the Projects folder from previous lessons.
This gives you a cleanup folder containing two files (scratch.txt and keep.txt), an empty folder (empty-folder), and a logs folder with one file inside it (monday.log). Before removing anything, inspect the exact target with ls -l:
The first listing confirms exactly what's inside cleanup right now — two folders and two files, nothing more. The second listing confirms that scratch.txt is a real file sitting at that exact path. This is the last moment you get to double-check before deleting it, so it's worth taking seriously every single time, not just when a mistake feels likely.
