3

I want to find all folders within a given folder that contain no files (but folders are ok). This needs to be recursive - it looks in all child folders.

I can find folders that are completely empty using the Number if Items search criteria set to less than 1. However, this does not return folders that have other folders inside them.

I am basically trying to delete folders that had files in that I have deleted the contents from using a previous search.

dunxd
  • 658

1 Answers1

4

Here is a terminal command

find . -type d -empty

And if you want to delete these files :

find . -type d -empty -delete
Matthieu Riegler
  • 21,486
  • 11
  • 59
  • 97
  • That finds empty directories in the current working directory, but not empty directories inside it. How do I make this recursive? – dunxd Jan 20 '13 at 01:40
  • It turns out that the folders have some hidden files in, so they aren't returned at all with this command :-( – dunxd Jan 20 '13 at 01:42
  • 2
    @dunxd If they are .DS_Store files, you can delete them with find ~/Folder -name .DS_Store -delete. – Lri Jan 20 '13 at 14:05