thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

macOS: remove all empty directories

• 131 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

For some odd reason my Calibre backup to cloud storage had a bunch of empty directories. I’ve been meaning to remove them, but it’s cumbersome to do so from the web client.

Instead, let’s do it from a local client.

Upon installing the cloud storage software, a local directory is exposed under /Users/$USER/Library/CloudStorage (macOS).

My first instinct is to use find(1):

shell
$ find -empty -type d -delete

However that does not work on macOS:

find: illegal option -- e
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

My second go to choice is fd(1):

shell
$ fd -t e -x rmdir

…this lists all empty directories and invokes rmdir on each of them.