Find Directories with Two or More Files

filesfind

I want to find a subdirectory of the current directory, which (that is the subdirectory) contains 2 or more regular files.

I am not interested in directories containing less than 2 files, neither in directories which contain only subdirectories.

Best Answer

Here is a completely different approach based on GNU find and uniq. This is much faster and much CPU-friendly than answers based on executing a shell command that counts files for each directory found.

find . -type f -printf '%h\n' | sort | uniq -d

The find command prints the directory of all files in the hierarchy and uniq only displays the directories that appear at least twice.