Find directories without files on Unix / Linux

I have a list of directories

/home /dir1 /dir2 ... /dir100 

Some of them have no files. How can I use Unix find for this?

I tried

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

It doesn't seem to work.

+7
linux unix find
source share
5 answers

Does your find have the -empty predicate?

You can use find . -type d -empty find . -type d -empty

+11
source share

If you are a zsh user, you can always do this. If you do not, perhaps this will convince you:

 echo **/*(/^F) 

**/* will expand to each child node of the current working directory, and () is the glob classifier. / restricts matching to directories, and F limits matching to nonempty. Negating this parameter with ^ gives us all the empty directories. See the zshexpn man for more details.

+1
source share

-empty reports empty sheets. If you want to find empty trees, look at: http://code.google.com/p/fslint/source/browse/trunk/fslint/finded

Please note that the script cannot be used without other support scripts, but can you install fslint and use it directly?

+1
source share

You can also use:

 find . -type d -links 2 

. and .. both are considered a link, like files.

+1
source share

Answer Pimin Konstantin Kefalou prints folders with only two links and other files (d, f, ...).

The easiest way I've found is this:

 for directory in $(find . -type d); do if [ -n "$(find $directory -maxdepth 1 -type f)" ]; then echo "$directory" fi done 

If you have a name with spaces, use quotation marks in the $ directory.

You can replace. on your help folder.

I could not do this with a single find statement.

0
source share

All Articles