tags:

views:

98

answers:

3

I have a list of directories

/home
  /dir1
  /dir2
  ...
  /dir100

Some of them have no files in it. How can I use Unix find to do it?

I tried

find . -name "*" -type d -size 0 

Doesn't seem to work.

+2  A: 

Does your find have predicate -empty?

You should be able to use find . -type d -empty

David M
+1  A: 

If you're a zsh user, you can always do this. If you're not, maybe this will convince you:

echo **/*(/^F)

**/* will expand to every child node of the present working directory and the () is a glob qualifier. / restricts matches to directories, and F restricts matches to non-empty ones. Negating it with ^ gives us all empty directories. See the zshexpn man page for more details.

jasonmp85
+1  A: 

-empty reports empty leaf dirs. If you want to find empty trees then have a look at: http://code.google.com/p/fslint/source/browse/trunk/fslint/finded

Note that script can't be used without the other support scripts, but you might want to install fslint and use it directly?

pixelbeat