OS X Tip – Use the CLI for Spotlight
Spotlight is a cool feature in 10.4 and 10.5 that allows you to perform really quick searches for files or words in a file, such as a PDF or a document or even a email message. Since the entire OS X filesystem is indexed, you can search using the CLI rather than the Magnifying Glass in the Finder. What is the benefit? A couple of reasons.
Firstly, I think that it is a bit faster. Secondly, You can script out routine searches or use standard Unix commands such as grep.
Let me give you an example. I am looking for a file that has the word SBS in it. Open a terminal window and type:
greg[citation] % mdfind SBS
It will return a list of all the files that match that search string that either contain the word SBS in the file name or the word SBS is found in that file. If you get an exhaustive return on your find, you can get more granular and do a grep. Let’s assume I am looking for any Excel document.
greg[citation] % mdfind SBS | grep xls
This will search out only Excel files. Once I found the file I was looking for, I can use Quicklook from the CLI to view that file. Here is an example:
greg[citation] % qlmanage -p “/Users/greg/Documents/SBS/Spreadsheet.xls”
This will open up a Quicklook window the same way you would from the Finder.
Enjoy.