Sub topic 8
Exact Phrases and AND, OR, NOT
This chapter assumes you can open Spotlight with the keyboard, read its result list, and run a basic file search by name or content. You should also know the kind: keyword from the previous chapter. Here you will learn how Spotlight combines words, how to force an exact phrase, and how to use AND, OR and NOT to include or exclude results.
How Spotlight reads a multi-word query
When you type more than one word, Spotlight does not look for the words as a phrase. It treats the query as a list of terms that must all match, in any order and in any position. The terms can match in different places. One word can match the file name, another the text inside, and a third a metadata field such as the author.
This is an implicit AND. The query budget 2026 finds a spreadsheet named "Budget" that contains the number 2026 somewhere in its cells. It also finds a note that mentions both words in unrelated paragraphs.
Implicit AND is usually what you want. It becomes a problem in two cases:
- You remember a specific sequence of words, and the loose match returns too many files.
- A common word you typed pulls in files you do not want.
Exact phrases and the operators solve these two cases.
Exact phrases with quotation marks
Put straight double quotation marks around words to require them next to each other, in that order.
"quarterly report"Without the quotes, this query also matches a file that contains "report" on page 1 and "quarterly" on page 9. With the quotes, only text where the two words are adjacent matches.
Keep these details in mind:
- Quotes work on content and names. A phrase can match inside a document's text or in a file name. A phrase that appears in a file name with a hyphen or underscore, such as
quarterly_report_final.pdf, may not match a quoted phrase with a space. Spotlight treats those characters as separators in many cases, but results vary. If a phrase fails, try the words without quotes and addname:to narrow it down. - Letter case and accents are usually ignored.
"Quarterly Report"and"quarterly report"find the same files. - Quote only what you need. A long quoted sentence fails if the document uses a slightly different wording, a line break in the middle, or a different hyphenation. Two or three distinctive words are more reliable.
- Use straight quotes. If you paste a query from a word processor, curly quotes (“ ”) may be inserted, and Spotlight can then read them as ordinary characters. Retype the quotes if a pasted query behaves strangely.
The three operators
Spotlight understands AND, OR and NOT. They must be typed in capital letters. A lowercase or is treated as an ordinary word to search for, so the query invoice or receipt requires all three words to appear.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| AND | Both terms must match | `tax AND 2025` | Items that match both |
| OR | Either term may match | `invoice OR receipt` | Items that match one or both |
| NOT | Exclude the next term | `budget NOT draft` | Items about budget that do not match "draft" |
AND
Because plain words already combine with AND, you rarely need to type it. Writing tax AND 2025 and tax 2025 gives the same results. It is still useful for readability when you share a query or write it down.
OR
OR widens a search. It suits cases where you do not remember which of several words the file uses.
invoice OR receiptThis matches a document that contains "invoice", one that contains "receipt", and one that contains both. OR is the operator that most often changes the result count in a visible way, so it is a good first thing to try when a search returns too little.
NOT
NOT removes results. Place it before the term you want to exclude.
budget NOT draftThis shows items that match "budget" and drops any that also match "draft". Two points matter here:
- NOT applies to the word right after it. To exclude a phrase, quote it:
report NOT "first draft". - NOT removes a file if the excluded word appears anywhere that Spotlight searches, including the body text and metadata. A final report that says "see the earlier draft" in one paragraph disappears from the results. If good files vanish, the excluded word is probably too common.
Combining phrases, operators, and keywords
You can mix all of these in one query. Keywords such as kind: and name: act as additional terms that must match.
"quarterly report"
budget NOT draft
invoice OR receipt
kind:pdf taxHere are some realistic combinations:
kind:pdf "annual summary" NOT draft
kind:image vacation OR holiday
name:invoice NOT "past due"Read each one from left to right as a list of requirements:
kind:pdf "annual summary" NOT draftfinds PDFs that contain the phrase "annual summary" and do not match "draft".kind:image vacation OR holidayis the one that surprises people. Without grouping, it is not guaranteed thatkind:imageapplies to both sides of the OR. Some results may be images about vacations, while others may be non-images that match "holiday". Check the results, and if kinds are mixed, run two searches or add a secondkind:term to the right side.name:invoice NOT "past due"finds items with "invoice" in the file name and no match for the phrase "past due".
Common errors
The same few mistakes cause most problems with these queries.
| Symptom | Likely cause | Fix |
|---|---|---|
| OR query returns only files with both words | `or` typed in lowercase | Type `OR` in capitals |
| Quoted phrase returns nothing | Words are not adjacent in the file, or the phrase spans a line break | Shorten the phrase or remove the quotes |
| Expected file is missing after NOT | The excluded word appears elsewhere in the file | Use a more specific word or a quoted phrase |
| Query pasted from a document behaves oddly | Curly quotes instead of straight quotes | Retype the quotation marks |
| Results mix kinds in an OR query | `kind:` applied to only one side | Search each side separately |
| A known file never appears | File is not indexed | Check indexing status, covered in the troubleshooting chapter |
The same ideas in Terminal
The mdfind command supports plain-text queries, but its structured query language has its own operators. In that syntax, && means AND, || means OR, and ! means NOT. A trailing c after a quoted value makes the comparison case-insensitive.
This query finds PDFs in your Documents folder whose text contains "invoice":
mdfind -onlyin ~/Documents "kMDItemContentType == 'com.adobe.pdf' && kMDItemTextContent == 'invoice'c"This one is the OR equivalent for file names, matching either "invoice" or "receipt" anywhere in the name:
mdfind -onlyin ~/Documents "kMDItemDisplayName == '*invoice*'c || kMDItemDisplayName == '*receipt*'c"And this one excludes names containing "draft":
mdfind -onlyin ~/Documents "kMDItemDisplayName == '*budget*'c && !(kMDItemDisplayName == '*draft*'c)"Because the shell treats ! specially in some interactive shells, keep the whole query inside double quotes as shown, and test it on a small folder first. The query language is explained in more detail in the chapter on mdfind and mdls.
A repeatable workflow
When a search is too broad or too narrow, adjust it in small steps:
- Start with two or three plain words.
- If you get too many results, add a distinctive word or put a known phrase in quotes.
- If you still see the wrong files, add
NOTwith a word that appears only in the unwanted ones. - If you get too few results, remove quotes, then try
ORwith a synonym. - Add
kind:last, to filter by file type once the text part is working.
Changing one thing at a time tells you which part of the query caused a change.
Exercise
You search report NOT draft and a final report you know exists is missing. It does mention the earlier draft in one paragraph. What happened, and how could you find it while still hiding most drafts?
Show answer
NOT removes any item that matches the excluded word anywhere Spotlight searches, including body text, so the final report is removed because it contains "draft". Use a narrower exclusion such as report NOT "first draft", or exclude by file name with a keyword such as report NOT name:draft, so only files whose names contain "draft" are hidden.
Exercise
You type invoice or receipt and get only files that contain all three words, including the word "or". Why, and what is the corrected query?
Show answer
Operators must be in capital letters. The lowercase or is treated as an ordinary word that must match. The corrected query is invoice OR receipt.