Latest in Shell

Image credit:

A (slightly) simpler command-line Spotlight search

Share
Tweet
Share
Save

Sponsored Links

Erica mentioned mdfind a little while ago. It's not a brand new tool, but there hasn't been a great deal of discussion surrounding it. For shell scripters and Terminal junkies, it's a goldmine of search goodness that can make you never want to key out find . -name "letsgogetcoffeewhilewewait.rb" or even locate didcronupdatethedb.yet again.

There are two mdfind options mentioned at Mac OS X Hints that are worth a mention, one found only in the man page, and one found only in the usage info. The former being "-interpret", which allows the advanced Spotlight query syntax to be used on the command line as if typed into the Spotlight window, turning mdfind "kMDItemContentType == 'public.jpeg'" into mdfind -interpret "kind:jpeg". Its opposing force would be "-literal", which forces a literal interpretation of the query string. Any qualified Spotlight query should be usable with "-interpret", so go ahead with mdfind -interpret "kind:image flash:1 modified:<=1/1/08 ex-girlfriend" to find those late-night pictures of last year's special someone. That would take a lot of metadata work to pull off without "-interpret".

The second option mentioned isn't in the man page, but you'll see it in the usage info if you run mdfind with no parameters. It's the "-s" option that loads saved searches. It will look in ~/Library/Saved Searches unless a path is specified. So you can save a search in Spotlight called "PDFs from yesterday" and run mdfind -s "PDFs from yesterday" to launch the same search at the command line. See, I had to throw a "normal" search in there to keep you on your toes.

Terminal jockeys can mix these up with a few pipes, stir in some perl and sprinkle in a little awk to get some really great Spotlight soufflé. Of course, if you don't like the command line and you're still reading this, you're a downright hardy trooper and I commend you. Go have a cup of coffee, you deserve it.

[via Mac OS X Hints]
In this article: shell, spotlight, Terminal
All products recommended by Engadget are selected by our editorial team, independent of our parent company. Some of our stories include affiliate links. If you buy something through one of these links, we may earn an affiliate commission.
Share
Tweet
Share
Save

Popular on Engadget

The 2019 Engadget Holiday Gift Guide

The 2019 Engadget Holiday Gift Guide

View
BioWare may revamp 'Anthem' in a bid to save it

BioWare may revamp 'Anthem' in a bid to save it

View
Simpsons World shuts down as episodes move to Disney+

Simpsons World shuts down as episodes move to Disney+

View
Huawei's foldable Mate X smartphone goes on sale in China

Huawei's foldable Mate X smartphone goes on sale in China

View
Redbox will stop selling Disney movie codes as part of settlement

Redbox will stop selling Disney movie codes as part of settlement

View

From around the web

Page 1Page 1ear iconeye iconFill 23text filevr