Commandline Spotlight tricks

So you can list the information about a file by using the commandline tool ‘mdls’ (ie metadata ls). This will give you a big list of everything the system knows about the file (try it on some QuickTime movie files or images).

You can also use it by specifying an attributeName to list. For example to get the version info of a file from the commandline you can look for the kMDItemVersion attributeName

>mdls -name kMDItemVersion /Applications/
/Applications/ -------------
kMDItemVersion = "2.0.4"

You could of course use mdfind to search the Spotlight database for items with the same key, ie

>mdfind "kMDItemVersion == '2.0.4'"            

Of course this assumes that your Spotlight database is currently up to date. Which really it should be, as Spotlight monitors disk file updates, but frequently it seems that it isn’t.

Leave a Reply

Your email address will not be published. Required fields are marked *