Wed Apr 7 15:47:00 EEST 2010

Howto delete empty directories in GNU /Linux with find linux command

Ever wondered how you can delete all the empty directories in Linux?
I bet you did, there are many ways to achieve that in GNU/Linux, however here is one way you might go:
First it is probably a good idea to list the empty directories and examine the empty directories before you take the next step and execute a command to delete them:

find . -depth -type d -empty


Now after you take a close look in the directories, next step to partake is delete the directories.

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


Be aware that in the above examples, the first one would list all directories in your current directory in which you
execute the command, the second example will delete all the empty directories starting from your current directory unto the deepest located empty directory in the directory tree.