Skip to Content

Free TUAW iPhone app -- try it now!
AOL Tech

Filed under: Software, Terminal Tips

Spotlight from the Command Line

0xFE (pronounced "254" I suppose...) has a very nice how-to up showing how to use Spotlight 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 displays the metadata associated with a specified file. e.g.

% mdls Television\ copy.jpg Television copy.jpg ------------- 
kMDItemAttributeChangeDate = 2006-11-29 11:10:52 -0700 kMDItemBitsPerSample
= 32 kMDItemColorSpace = "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" kMDItemDisplayName
= "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.

jobs & resumes
iPhone developer

Groupon - Chicago, IL (1 weeks ago)

See More Relevant Jobs ›

Tip of the Day

Holding the Command key (aka the Apple key) and pressing Tab will cycle through your open applications. It's easier to Cmd-Tab if you are Copy (Cmd-C) and Pasting (Cmd-V) to and from various applications.


Follow us on Twitter!
 TUAW [Cafepress]

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
Storyist 2.0
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor

 

More Apple Analysis

AOL Radio TUAW on Stitcher