My favorite macOS command Linen #blog

2 min read Original article ↗

For macOS developers, efficiency is everything. Enter

mdfind

, a command that marries speed with precision. What makes it stand head and shoulders above the rest?

mdfind

is like having Spotlight’s capabilities in the command line. While many search tools painstakingly peruse your filesystem,

mdfind

operates on a shortcut. It pulls results from the 'metadata store' or

mdstore

- a continuously updated catalog. Imagine pulling a specific card from a neatly organized card catalog versus skimming through an entire bookshelf.

Here's how

mdfind

sizes up against

find

: Speed -

mdfind

excels with its indexed search, while

find

delves deep into the filesystem, making it relatively slower. Scope -

find

restricts itself to file attributes like name, size, or date. Meanwhile,

mdfind

penetrates metadata, fishing out intricate details such as tags or document content. Flexibility -

find

pulls ahead in adaptability, with a diverse range of operators for detailed searches, an aspect where

mdfind

plays catch-up.

If you're itching to put

mdfind

to work, here are some straightforward commands:

bash Copy code

mdfind -onlyin ~/Documents "pdf"

bash Copy code

mdfind -onlyin ~/Downloads "image"

bash Copy code

mdfind -name "report"

bash Copy code

mdfind "unicorn"

Using

mdfind

, file hunting on macOS transforms into a swift, precise adventure. Once you take it for a spin, it's likely to find a permanent spot in your developer toolkit!