Remove Empty Dirs

This will remove empty directories on any *nix based OS. Of course you have to sudo the command or run it as root depending on how things are configured.

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

The following code will dump it to a list first, then you can review the list and count the number of lines before deleting the empty dirs.

find -depth -type d -empty > list_for_review
cat list_for_review | wc -l
find -depth -type d -empty -exec rmdir {} \;

If you just want to count the number of empty dirs use the following command.

find -depth -type d -empty | wc -l

Have fun removing dirs. :D

This entry was posted in Blog. Bookmark the permalink.

Comments are closed.

blog comments powered by Disqus