Delete a directory and everything in it

Destructive
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Permanently removes a directory tree after inspecting what it contains — the careful version of rm -rf.

filesdeletecleanupremove

Confirmation required

This recipe is destructive and requires confirmation — confirm you understand the impact before running any command below.

Parameters

Directory to delete, with everything under it.

Commands

See the directory's size and a sample of what will be deleted

du -sh "<directory>" && find "<directory>" | head -n 20

Permanently delete the directory and all its contents

rm -rf "<directory>"

Verification

ls "<directory>"

An error like "No such file or directory" — the directory is gone.

Undo

Not undoable

rm -rf bypasses the trash; the contents are unrecoverable without backups. Verify the path and run the inspection step first, every time.

Pitfalls

  • An empty or mistyped variable can turn the path into "/" or the home directory — echo the path before deleting.
  • If the directory is a symlink, rm -rf deletes the link's target contents when a trailing slash is used; check with ls -ld first.
  • Prefer moving to the trash (macOS "mv to ~/.Trash", or a tool like trash-cli) when recoverability matters.

Related