10.4: A collection of 'Spotlight from Terminal' tips
Mar 27, '06 05:31:00AM • Contributed by: Anonymous
Mar 27, '06 05:31:00AM • Contributed by: Anonymous
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
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 == '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.]
•
[14,639 views]
