mdfind: Combining kMDItemTextContent & kMDItemContentType

I'm trying to use the Terminal command mdfind to search my file system for text file .rtf containing a certain pattern as in the following example:


mdfind -onlyin '/Volumes/TO Video/Youtube Opere' 'kMDItemTextContent == "Sierra"' && 'kMDItemContentType == "*.rtf"'


This does NOT work: it returns "zsh: no matches found"


But both the following return results as expected!:

a. mdfind -onlyin '/Volumes/TO Video/Youtube Opere' 'kMDItemTextContent == "Sierra"'

returns all files in the folder (even .pdf) containing "Sierra", and most of them are .rtf

b. mdfind -onlyin '/Volumes/TO Video/Youtube Opere' 'kMDItemContentType == "*.rtf"'

returns all .rtf files the folder, no matter what they contain


So I guess I miss something in the mdfind syntax!

May I use "||" or "&&" in a query ? according to (OLD?) description of mdfind they are supposed to work...


Can anybody help me?


Thanks!

Piero

Posted on Jun 22, 2026 12:23 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 22, 2026 2:07 AM

Try this:

mdfind -onlyin /Volumes/TO\ Video/Youtube\ Opere 'kMDItemTextContent == "*sierra*"c && kMDItemContentType == "public.rtf"'


One set of single quotes to surround your compound metadata attributes and the trailing 'c' on the *sierra* is a case-insensitive flag.


Note that RTFD content is not searched, nor will it after adding a grouped public.rtf || public.rtfd content types to the above.


Tested: macOS 26.5.1

4 replies
Question marked as Top-ranking reply

Jun 22, 2026 2:07 AM in response to piero.fiorani

Try this:

mdfind -onlyin /Volumes/TO\ Video/Youtube\ Opere 'kMDItemTextContent == "*sierra*"c && kMDItemContentType == "public.rtf"'


One set of single quotes to surround your compound metadata attributes and the trailing 'c' on the *sierra* is a case-insensitive flag.


Note that RTFD content is not searched, nor will it after adding a grouped public.rtf || public.rtfd content types to the above.


Tested: macOS 26.5.1

mdfind: Combining kMDItemTextContent & kMDItemContentType

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.