Home » Need to delete tons of empty folders?

Need to delete tons of empty folders?

If you have lots and lots of websites, you almost undoubtedly at SOME point or another have found yourself staring at hundreds, perhaps THOUSANDS, of empty folders because of some script or another that you ran. How do you get rid of them all without going insane in the process???

I was just faced with this dilemma, and of course a little web searching turned up the solution!

This is a shell (SSH) command, so you must have shell access in order to execute it. The command is:

find -depth -type d -empty -exec rmdir {} \;

I found it at this page: http://duramecho.com/ComputerPrograms/DeleteEmptyDirectories/index.html

It works great! What it will do is to delete all empty folders, recursively, below the directory that you are now in. So if you wanted to delete all empty folders located below public_html for the user “website”, then you would need to navigate to /home/website/public_html/ and then execute the script command.

And of course, you could even put this in a CRON if you wanted to just routinely delete all empty folders for a particular domain, if you have some process that tends to create them.

I hope this helps someone else as much as it has helped me!

Name of author

Name: macroking

Leave a Reply

Your email address will not be published. Required fields are marked *