Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save princeppy/7bdd8bbac22d268d6ef1141bb3e41bf2 to your computer and use it in GitHub Desktop.
Save princeppy/7bdd8bbac22d268d6ef1141bb3e41bf2 to your computer and use it in GitHub Desktop.

Recursively Remove Empty Subfolders on macOS

Simple one-liner to remove empty directories recursively

find /Volumes/Projects/nodejs/eCard -type d \
    -empty -depth \
    -not -path "*/.git" -not -path "*/.git/*" \
    -delete

Or with confirmation for each directory

find /Volumes/Projects/nodejs/eCard -type d \
    -empty -depth \
    -not -path "*/.git" -not -path "*/.git/*" \
    -ok rm -rf {} \;

To see what would be removed without actually deleting

find /Volumes/Projects/nodejs/eCard -type d \
    -empty -depth \
    -not -path "*/.git" -not -path "*/.git/*" \
    -print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment