Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to search for an exact phrase using the mdfind utility? For example, I created two text documents titled "test1" and "test2". The contents of "test1" are:

I love Apple

And the contents of "test2" are:

Apple love I

When I type this in terminal (I placed both files in ~/Documents):

mdfind "I love Apple" -onlyin ~/Documents

I get:


How would I search for the exact phrase "I love Apple" so mdfind only returns results containing those words in that order (in this case only "test1.txt")?

share|improve this question
up vote 5 down vote accepted

You need to escape your quotes like so:

mdfind \"I love Apple\" -onlyin ~/Documents

This results in just the one document being found:


Without escaping them, I don't think the quotes actually get passed to the mdfind command, they're just interpreted by your shell to say that I love Apple is a single argument. With the backslash-escaping, the argument then includes the quote characters.

share|improve this answer
Thanks so much! – pasawaya Oct 15 '12 at 2:26

The double quotes can also be placed inside single quotes:

mdfind '"exact phrase"'

This would search only in the contents:

mdfind 'kMDItemTextContent=="*exact phrase*"'
share|improve this answer
Thanks. This worked too, but drfrogsplat answered first. – pasawaya Oct 15 '12 at 6:25

Your Answer


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.