The following will remove all empty directories (those with no children). As it does so depth-first (bottom-up), it will remove directories with only (empty) directories as children. Beware that, in find, the order of arguments matters.
find testdir -depth -type d -empty -delete
Drop -delete to see the files and directories matched, however note that because of -depth, parent dirs that would become empty will not be listed (beware that -depth is implied by -delete in some find implementations). Remove the -type d if you would to also like to delete empty files.
For example:
$ mkdir -p testdir/foo/bar/baz; touch testdir/foo/afile.txt
$ find testdir -printf '%y %p\n' | tee before.txt
d testdir
d testdir/foo
d testdir/foo/bar
d testdir/foo/bar/baz
f testdir/foo/afile.txt
$ find testdir -depth -type d -empty
testdir/foo/bar/baz
$ find testdir -depth -type d -empty -delete
$ find testdir -printf '%y %p\n' | tee after.txt
d testdir
d testdir/foo
f testdir/foo/afile.txt
$ diff -u {before,after}.txt | tail +4
d testdir
d testdir/foo
-d testdir/foo/bar
-d testdir/foo/bar/baz
f testdir/foo/afile.txt
answered 2010-05-11T13:39:39.690