| name | mdfind |
| description | Search your entire Mac instantly using Spotlight's CLI. No RAG, no indexing setup, works out of the box. |
| homepage | https://x.com/_chenglou/status/2018915948456214940 |
| metadata | {"openclaw":{"emoji":"🔍","requires":{"bins":["mdfind"]},"platforms":["darwin"]}} |
mdfind 🔍
macOS Spotlight as a terminal tool. Fuzzy & exact search across your entire computer in real time.
No RAG. No external tools. No prescriptive structure. Built-in and optimized.
Source: @_chenglou
Why Use This
- Instant — Spotlight index is always up to date
- Comprehensive — Searches file names, contents, and metadata
- Zero setup — Already on every Mac
- Fast — Highly optimized native search
Basic Usage
mdfind "statistical learning"
mdfind -onlyin ~/clawd "pipeline"
mdfind -live "TODO"
File Type Filters
mdfind "kMDItemContentType == 'com.adobe.pdf'"
mdfind "kMDItemContentType == 'net.daringfireball.markdown'"
mdfind "kMDItemContentType == 'public.image'"
mdfind "kMDItemFSName == '*.py'"
mdfind "kMDItemContentType == 'org.openxmlformats.wordprocessingml.document'"
Combining Queries
mdfind "kMDItemContentType == 'com.adobe.pdf' && kMDItemTextContent == '*methods*'"
mdfind "kMDItemContentType == 'net.daringfireball.markdown' && kMDItemFSContentChangeDate >= \$time.today"
mdfind "kMDItemAuthors == 'Smith'"
mdfind "kMDItemFSSize > 100000000"
Date-Based Searches
mdfind "kMDItemFSContentChangeDate >= \$time.today(-7)"
mdfind "kMDItemFSCreationDate >= \$time.this_week"
mdfind "kMDItemFSContentChangeDate >= \$time.today"
Name-Based Searches
mdfind "kMDItemFSName == 'README.md'"
mdfind "kMDItemFSName == '*.qmd'c"
mdfind "kMDItemDisplayName == '*grant*'c"
Useful Metadata Attributes
| Attribute | Description |
|---|
kMDItemFSName | File name |
kMDItemDisplayName | Display name |
kMDItemTextContent | File contents |
kMDItemContentType | UTI type |
kMDItemFSSize | File size (bytes) |
kMDItemFSCreationDate | Created date |
kMDItemFSContentChangeDate | Modified date |
kMDItemAuthors | Authors |
kMDItemTitle | Document title |
kMDItemKeywords | Keywords/tags |
Get All Attributes for a File
mdls /path/to/file.pdf
Common Patterns
Find project files
mdfind -onlyin ~/clawd/Projects "EEG"
Find recent work
mdfind "kMDItemContentType == 'net.daringfireball.markdown' && kMDItemFSContentChangeDate >= \$time.today(-3)"
Find by content + type
mdfind "kMDItemFSName == '*.py' && kMDItemTextContent == '*import torch*'"
Count results
mdfind -count "kMDItemContentType == 'com.adobe.pdf'"
Output Options
mdfind -count "query"
mdfind -0 "query" | xargs -0 ls -la
mdfind -onlyin . "TODO" | head -20
Tips
- Use
-onlyin to scope searches and speed up results
- Wildcards use
* and must be quoted: '*pattern*'
- Case-insensitive by adding
c suffix: '*readme*'c
- Combine with grep for content filtering:
mdfind "query" | xargs grep -l "specific"
- Check indexing status:
mdutil -s /
Community Insights
From the original thread:
@udaysy: "been using ripgrep for everything but mdfind would catch stuff outside the project dir too right? like config files scattered across ~/"
Yes! Unlike rg or grep which search from cwd, mdfind searches your entire indexed filesystem by default. Great for finding those scattered config files.
@sentigen_ai: "Also works great paired with fd for when you know the rough name but not the path. mdfind for fuzzy semantic queries, fd for fast exact matches."
Recommended combo:
mdfind — fuzzy semantic search (content + metadata)
fd — fast exact filename matching
rg — fast exact content grep
@sughanthans1: "can it look inside files or just file names"
Both! Spotlight indexes file contents for supported types (PDF, Word, text, code, etc.). Use kMDItemTextContent to explicitly search inside files.
Limitations
- Only searches Spotlight-indexed locations (not
/tmp, external drives unless enabled)
- Some file types may not have content indexed
- Check
mdutil -s /path to verify indexing status
TL;DR: mdfind "your query" — instant full-text search across your Mac. Add -onlyin ~/folder to scope it. 🔍