Latest in Shell

Image credit:

A (slightly) simpler command-line Spotlight search

Brett Terpstra
January 4, 2008
Share
Tweet
Share

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

Popular on Engadget

The 2020 Engadget Holiday Gift Guide

The 2020 Engadget Holiday Gift Guide

View
Scientists find neutrinos from star fusion for the first time

Scientists find neutrinos from star fusion for the first time

View
The best Black Friday tech deals that are already available

The best Black Friday tech deals that are already available

View
Apple's Intel-powered MacBook Air falls to $799 ahead of Black Friday

Apple's Intel-powered MacBook Air falls to $799 ahead of Black Friday

View
'Mechwarrior 5' will arrive on Xbox in spring 2021

'Mechwarrior 5' will arrive on Xbox in spring 2021

View

From around the web

Page 1Page 1ear iconeye iconFill 23text filevr