List all empty folders

I have a bunch of nested folders. Most folders contain files. Some contain hundreds of thousands of files. Some are empty.

I want to get a list of all empty folders. However, when I run:

find -type d -empty

it takes a very long time to run, a lot longer than it takes to run just find -type d. I suspect that -empty is checking all files to see if they are empty, then -type d is skipping the files.

So is there:

1) a way to optimize find so that it will a) find all folders, then b) list the empty ones?

or

2) a different command (or commands) that I could use to get this list?


Try this

find / -xdev -type d -exec find {}  -maxdepth 0 -empty  \;

or the marginally faster

find / -xdev -type d | xargs -I{} find {} -maxdepth 0 -empty

find -type d | xargs -I{} find {} -empty