Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there any way to search a specific type of file using Spotlight? I remember there was a special command or something that I had to put in front of the search phrase but I cannot remember it now.

For example, if I want to search only PDFs for a particular phrase in Spotlight, what would I do?

share|improve this question

5 Answers 5

up vote 15 down vote accepted

Search by Kind One of the most useful ways to narrow down a search is by using the kind: keyword. This allows you to restrict your list of results to a certain file format. For instance, if you type time machine kind:pdf, Spotlight will pull up only PDF files containing the words time and machine. You can also limit your search to e-mail messages, music files, System Preferences, applications, and more.

While the original Spotlight recognized only a limited number of file types, the Leopard version can look for files created by specific applications, as well as certain file formats. Searching for kind:mp3 or kind:tiff will find files in one of those formats, and searching for kind:pages or kind:powerpoint will show only documents created in one of those programs. For a list of useful keywords, see “My Kind of Keyword.” But remember, for the keywords to work, you must have the appropriate categories enabled in Spotlight’s preferences.

you can get more info here or here.

alt text

share|improve this answer
    
Ah, yes! This was the command that I needed! Thank you very much. :) –  JFW Aug 27 '10 at 8:34
    
This is so AWESOME. I didn't know you could do this. Thanks very much. –  Henry Sep 11 '10 at 22:08
2  
You should be more clear that this answer was copied and pasted from Macworld.com. –  Dori Sep 13 '10 at 8:14
  1. Open a Find Window (cmd-f) or do a spotlight search and select "show all"
  2. Hit the little "+" icon (to the right of the 'save' button)
  3. Select File Type as a search criteria and select the correct one.
  4. Rerun the search.

(Disclaimer, I'm not on a Mac right now :( so my exact instructions might be a little off).

share|improve this answer

It's already been answered, but here's my 2 cents.

Via Bash through the terminal

find ~ -type f -name '*pdf' or find ~ -iname '*pdf'

or you can use this to search for a string in a file:

find ~ -iname '*txt' | xargs grep 'string you want'

This may not return anything on a pdf, but it will work on most other file types (text, php, py, html, etc).

share|improve this answer
1  
it's like grep :) –  Am1rr3zA Sep 11 '10 at 22:57
mdimport -A 

will give you every possible attribute available on your system

kMDItemKind is the attribute for files, but perhaps the above will suggest a better attribute to search on.

Then

mdfind "kMDItemKind == 'whatever'"

The syntax might make you shout out in disgust. I can personally attest that it ruins zsh completion. Still, Spotlight ( that's what this is ) indexes your stuff all the time anyway, and it's fast. Might as well use it. YMMV

share|improve this answer

The question "How to use Regex with spotlight" is marked as a duplicate of this for some reason, so I thought I would share how to do wildcard searching.

You can do wildcard searching in the Finder using a Kind of "Raw Query" with the kMDItemDisplayName attribute: Raw Query example

Raw Queries are essentially what you use with the mdfind command. I have more details on Raw Queries and using them in the GUI at http://superuser.com/a/491119/66255.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.