brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mdfind -live keeps a Spotlight search running in the terminal

Terminal
~/tips/tip-macos-mdfind-live

mdfind -live -onlyin ~/Downloads invoice

Keeps an mdfind search open and updates the match count as files change.

Most searches are a snapshot. mdfind has a mode that keeps watching after the first answer, which is a neat way to see files appear while something else is busy.

Add -live and mdfind first prints the matches it finds, then keeps running. When the results change, it updates the number of files that match the query. Press Ctrl-C to stop it.

mdfind -live -onlyin ~/Downloads invoice

Here the search sticks to the Downloads folder, thanks to -onlyin, and looks for “invoice”. Leave it running in a spare terminal tab while a mail client or a sync job drops files, and the count goes up as soon as Spotlight has indexed the new ones. The man page’s own example is mdfind -live skateboard.

I’d use this to answer one question: did the thing arrive yet? It saves you from running the same search over and over.

The caveat is that the live part reports a count, not a fresh list of paths, so you still run a normal mdfind afterwards to see which files they are. It also only sees what Spotlight indexes. A folder that is excluded from Spotlight, or a disk with indexing off, never shows up, however long you wait.

Further reading: mdfind.1 man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link