Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: A collection of 'Spotlight from Terminal' tips UNIX
Tiger only hintI just wrote a detailed article on using Spotlight from the Terminal. Here are a few tips from that article:

Example 1. A Basic Spotlight Query

The commandline version of Spotlight is mdfind. Simply provide your search query as a parameter and let it run.

evil:~/Desktop mohit$ mdfind Rails
/Users/mohit/Documents/Agile Development with Rails.pdf

The files that are listed also include files with content and metadata that matches the query expression.

Example 6. Finding Other Content

You can find images by querying for files with kMDContentTypeTree set to public.image.
$ mdfind "kMDItemContentTypeTree == 'public.image'"
How about we refine that to only images within our iPhoto library:
$ mdfind -onlyin ~/Pictures "kMDItemContentTypeTree == 'public.image'"
Much Better. Looking for Word documents?
$ mdfind "kMDItemContentType == ''"
Or maybe just PDFs?
$ mdfind "kMDItemContentType == 'com.adobe.pdf'"
Or Both?
$ mdfind "kMDItemContentType == '' || \
kMDItemContentType == 'com.adobe.pdf'"
Lets stick to plain-text:
$ mdfind "kMDItemContentTypeTree == 'public.text"
[robg adds: Some of these tips have been published here on macosxhints before, but I felt this was a nice all-in-one-spot summary worth sharing as a hint of its own.]
  • Currently 4.00 / 5
  You rated: 3 / 5 (6 votes cast)

10.4: A collection of 'Spotlight from Terminal' tips | 5 comments | Create New Account
Click here to return to the '10.4: A collection of 'Spotlight from Terminal' tips' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: A collection of 'Spotlight from Terminal' tips
Authored by: galendw on Mar 27, '06 06:27:35AM

Um, what happened to examples 2, 3, 4, and 5?

[ Reply to This | # ]
10.4: A collection of 'Spotlight from Terminal' tips
Authored by: owsla on Mar 27, '06 06:31:14AM
The other examples are on his blog, which he linked to above

[ Reply to This | # ]
10.4: A collection of 'Spotlight from Terminal' tips
Authored by: zane on Mar 27, '06 01:42:03PM

Good article. I've been wanting to learn how to better use Spotlight via. This saves me a lot of laborious Googling. Thanks!

[ Reply to This | # ]
From one web programmer to another...
Authored by: Lectrick on Mar 27, '06 07:46:36PM
Nice subtle Rails reference ;)

In /dev/null, no one can hear you scream

[ Reply to This | # ]

Authored by: lullabud on Mar 28, '06 09:43:34AM

This will definitely help me add features to my php and spotlight driven music search for my web share. :D

Now if iTunes would let you append multiple file comments or keywords rather than overwrite....

[ Reply to This | # ]