I 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/Rails4Days.pdf
/Users/mohit/Documents/Agile Development with Rails.pdf
/Users/mohit/Library/Mail/POP-foobar@mail.snip.com/INBOX.mbox/Messages/20455.emlx
/Users/mohit/Local/rails
/opt/local/lib/ruby/gems/1.8/cache/rails-1.0.0.gem
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/bin/rails
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/builtin/controllers/rails_info_controller.rb
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/html/index.html
/opt/local/lib/ruby/gems/1.8/gems/rails-1.0.0/html/images/rails.png
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 == 'com.microsoft.word.doc'"
Or maybe just PDFs?
$ mdfind "kMDItemContentType == 'com.adobe.pdf'"
Or Both?
$ mdfind "kMDItemContentType == 'com.microsoft.word.doc' || \
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.]
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060322141215752