OT: "find" command with branch/pipe

kevin beckford chiggsy at lazyweb.ca
Wed Nov 10 12:41:15 PST 2010


>> I am struggling with the find command, trying to find all files ending
>> with .h or .cpp in a certain directory.

On OS X?

Why use find when you have spotlight?

man mdfind

mdfind -name filename -onlyin some_directory

man mdls

mdls some_file.cpp  # this will show you what  the attributes are,
because they are named outlandishly obscure.


kMDItemContentType             = "public.c-plus-plus-source"

On my system that is the metadata given to cpp source files.

So:

mdfind -onlyin some_dir "kMDItemContentType = 'public.c-plus-plus-source'"

This correctly found all the C++ source files on my system.

Finally:  man mdimport

mdimport -L on my system gives me:

 mdimport -L
2010-11-10 12:38:42.483 mdimport[79281:903] Paths: id(503) (
   <snip>
     "/Developer/Applications/Xcode.app/Contents/Library/Spotlight/SourceCode.mdimporter",
   </snip>

you might need that importer.


More information about the macports-users mailing list