Search for folders that contain filetypes
-
23-02-2021 - |
Question
For example, how do you search for all folders that contain ".mp3" files (on OS X)?
Solution
I don't think it's possible using Finder, but you can easily find these folders via Terminal
find . -name '*.mp3' | sed 's|/[^/]*$||' | sort -u
Some explanations:
find
lists all files (and their paths) ending inmp3
in the current folder and everything "beneath" itsed
strips away the last part of each line produced byfind
which does not contain a/
(which practically results in the file name getting removed)- The result so far is a list of folders containing
mp3
files. If a folder contains more than one such file, it will be listed several times so we usesort -u
(unique) to remove duplicates while sorting.
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange