Mac Index Search – CLI Commands

Basic Search

mdfind "search term"

Search in a Specific Folder Only

mdfind -onlyin ~/Documents "search term"

Search by File Name

mdfind "kMDItemFSName == '*.pdf'"

Search by File Type

mdfind "kMDItemContentType == 'com.adobe.pdf'"

Show Metadata of a File

mdls /path/to/file.pdf

Live Search (stays open and shows new matches)

mdfind -live "search term"

Combined Attributes

mdfind "kMDItemAuthor == 'Max' && kMDItemContentType == 'com.adobe.pdf'"

Overview

CommandPurpose
mdfindSpotlight search
mdlsShow metadata
mdutil -s /Check index status
mdutil -E /Rebuild index (requires sudo)