Back to lessons

Hosting Operations

List Empty Directories as Cleanup Candidates

A cache tree may contain abandoned empty directories and you need to review them before cleanup.

Command

find /lab/disk-inode-cleanup/var/cache/app -xdev -depth -type d -empty -print

What changed

Nothing changes. The command prints empty directories without removing them.

Danger

safe

When to use it

Use before pruning empty cache or working directories after a migration, deploy, or failed job.

When not to use it

Do not delete empty directories that applications expect to exist unless startup or deploy code recreates them.

Undo or recovery

No undo needed because this command is read-only.

Expected output

Paths to empty directories under the selected cache tree.

demo script

Disposable terminal steps

  1. find /lab/disk-inode-cleanup/var/cache/app -xdev -maxdepth 3 -type d -print | sort
  2. find /lab/disk-inode-cleanup/var/cache/app -xdev -depth -type d -empty -print

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ find /lab/disk-inode-cleanup/var/cache/app -xdev -maxdepth 3 -type d -print | sort
/lab/disk-inode-cleanup/var/cache/app
/lab/disk-inode-cleanup/var/cache/app/empty-old
/lab/disk-inode-cleanup/var/cache/app/shards
/lab/disk-inode-cleanup/var/cache/app/shards/a
/lab/disk-inode-cleanup/var/cache/app/shards/b
::exit-code::0
$ find /lab/disk-inode-cleanup/var/cache/app -xdev -depth -type d -empty -print
/lab/disk-inode-cleanup/var/cache/app/empty-old
::exit-code::0

YouTube Short

Preview empty dirs.

Even empty-directory cleanup should start with a print-only pass. Some apps expect those paths to exist.

LinkedIn hook

Empty directories are low-risk candidates, but they still deserve a preview.

Question: Do you treat empty directories as safe to remove, or do you check app expectations first?

experiments

A/B tests to run

Metric: comment_rate

A: Empty is not always disposable.

B: Preview empty directories first.