There are probably several ways to do this in the Terminal. Here’s one, which calls find to search for .jpg files, then dirname on each filename to extract the full directory name, and finally uniq to remove duplicates.
find 'pathToLookUnder' -iname '*.jpg' -print0 | xargs -0 dirname | uniq
(Obviously, replace pathToLookUnder with the path to the folder you want to search in. Or cd to it first, and use . instead.)
This is structured as a pipeline: the filenames that find lists are passed on to dirname (using xargs to call it for each one) and the results then passed to uniq.
The ‘-print0’ and ‘-0’ flags work around problems with special characters. If any of the filenames contains a quote or similar, xargs would normally try to split there. To work around that, ‘-print0’ tells find to separate filenames with a zero byte; and ‘-0’ tells xargs to split only on zero bytes. So this should work for any filenames (that don’t contain newlines).
This will return the folder names in an unspecified order. You can of course append | sort if you want them ordered.
The results are listed on the terminal. You can instead save them to a file, by appending >filename.txt. Or you can copy them to the clipboard by appending | pbcopy (so they can then be pasted into other apps).
UPDATE: -iname '*.jpg' will find all files ending in ‘.jpg’ (or ‘.JPG’, or any combination). To search for multiple extensions, you can instead use a condition like:
'(' -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' ')'
(The parens ensure that the following ‘-print0’ will apply to them all. And the quotes prevent what’s in the parens being interpreted as commands for a subshell, or file attributes, depending on the shell.)




