How to recursively delete empty directories in a directory

How to recursively delete empty directories in a directory

The find command is a tool allowing you to run recursive file system operations. To only search for directories only (and not plain files) use the -type d expression. The GNU version of find supports the -empty use this to print all empty directories below your current directory.
$ find . -type d -empty -print
When you are happy that these directories are the ones to remove you can use -delete to delete all matches.
$ find . -type d -empty -delete

Categories: Posts