Tuesday, 28 February 2006

otlight from the Command Line

0xFE (pronounced "254" I su ose...) has a very nice how-to up showing how to use otlight metadata to find files from the command line. The post shows how the mdfind command goes beyond find, locate and various grep hacks to create flexible and powerful queries. Surprisingly enough, I couldn't find an mdfind man page (mdutil was there) but the mdfind command worked fine for me in Terminal.

A typical mdfind command goes something like mdfind Sadun, where Sadun is the search word. To limit the search to a particular folder use the -only flag. mdfind -only ~/Desktop Sadun.

The mdls command di lays the metadata a ociated with a ecified file. e.g.

% mdls Television\ copy.jpg Television copy.jpg ------------- 
kMDItemAttributeChangeDate = 2006-11-29 11:10:52 -0700 kMDItemBit erSample
= 32 kMDItemColor ace = "RGB" kMDItemContentCreationDate =
2006-11-29 11:10:19 -0700 kMDItemContentModificationDate = 2006-11-29
11:10:19 -0700 kMDItemContentType = "public.jpeg"
kMDItemContentTypeTree = ("public.jpeg", "public.image",
"public.data", "public.item", "public.content") kMDItemCreator
= "Adobe Photoshop CS2 Macintosh" kMDItemDi layName
= "Television copy.jpg" kMDItemFSContentChangeDate =
2006-11-29 11:10:19 -0700 kMDItemFSCreationDate =
2006-11-29 11:10:19 -0700 (...and so forth...)

It's a great post that goes into far more detail and is well worth a careful read.

No comments:

Post a Comment