Linux – Find empty directories and/or remove

By | August 24, 2015


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 !!

Are you looking for an web agency in Tokyo? Tokyo website design by Webguru Come talk to us in Shibuya
Check out -  Bash - How to echo an exclamation mark in your bash scripts

Leave a Reply