Tip 327Search Spotlight from Terminal

This is a tip for those who like to use the command-line prompt. To perform a Spotlight search at the command line, use the mdfind command. For example, to search for any documents that contain the term macintosh, you could type the following:

 
mdfind macintosh

The -onlyin command option will limit the search to a certain folder, which is useful if you want to find files that are within your Documents folder, for example. The following would search for files containing the term macintosh within your Downloads folder:

 
mdfind -onlyin ~/Downloads macintosh

An interesting additional command option is -count, which will display how many files there are that contain your search term, for example:

 
mdfind -count ...

Get Mac Kung Fu, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.