Linux – Find empty directories and/or remove

By | August 24, 2015
ilovebash

ilovebash

I needed this command and had to look around to try and find it. There is often a need on Linux to be able to find an empty directory, and maybe to remove it as well.

Find empty directories and/or remove

Find empty directories in the current directory using find -empty

find . -type d -empty

You can then use the following command to remove all empty directories under the current directory.

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

Be careful when you do this to always run the first command (without the -exec) first so you know what you are about to remove !!

Check out -  How to solve Wordpress login hack attempts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.