Tech Reflect

Tech Reflect

Share this post

Tech Reflect
Tech Reflect
Command-line search with Spotlight

Command-line search with Spotlight

Chris Hynes - cricket's avatar
Chris Hynes - cricket
Jun 10, 2017
∙ Paid

Share this post

Tech Reflect
Tech Reflect
Command-line search with Spotlight
Share

Spotlight can be powerful and fast, but lacks some precise control over the results. Typically you get far more results than you would ever need. The command-line interface unlocks more advanced functionality and you can also integrate it into your scripts.

The core command is “mdfind” and you could do “man mdfind” to see all the possibilties. However, here are a series of examples.

Simple

# Find every file that contains parakeet in the contents.

mdfind parakeet
# Restrict the search to a folder and ites subfolders (NOTE: Must be full path)

mdfind parakeet -onlyin /Users/admin/Pictures
# Display current matches and provide a live update when the number of matches changes. Great for testing you command but also to see live updates of things like a log file being created by your script.

mdfind parakeet -onlyin /Users/admin/Pictures -live
# Just display the live updating count. Less verbose and if you only care that it’s updating.

mdfind parakeet -onlyin /Users/admin/Pictures -live -count

Keep reading with a 7-day free trial

Subscribe to Tech Reflect to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Christopher Hynes
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share