Is there a command to execute in Bash that deletes all empty folders recursively until there is no empty folder in the tree? I could execute this:
find . -type d -empty | xargs -I '{}' rmdir {}
repeatedly until there is no more empty folders, but I am looking for something a bit more efficient. Especially since that to know whether there are empty folders left, I would have to execute the same command, i.e. two calls to find . -type d -empty in each iteration.
This is simple, given the GNU find utility:
find . -type d -empty -delete
This will delete empty directories; since the -delete option implies the -depth option, it will delete directories that only had empty directories underneath them, so there's no need to run it multiple times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With