Shell – Count how many directories have at least one file with specific extension

filesshell

How can I know how many directories (in current directory) have at least 1 file with a .mp3 extension.

No need recursion — directory structure from current dir is for example:

1/blabla.mp3
2
3/something.mp3
4
5

The command should return that there are 2 dirs with mp3 file(s).

Best Answer

find . -type f -name "*.mp3" -exec dirname {} \; | uniq | wc -l
Related Question