Assuming you have a complex filesystem from which you want to delete all empty directories and all directories containing empty directories recursively, while leaving intact the rest.
You can use the following command.
find . -type d -empty -delete;
The configuration we used is the following:
-type drestricts the results to directories only
-emptyrestricts to empty directories only
-deleteremoves the directories that matched
The above code will delete all directories that are either empty or contain empty directories in the current directory.
It will successfully delete all empty directories even if they contain a large number of empty directories in any structure inside them.
This post is also available in: Greek