Spotlight search
Syntax
mdfind [-live] [-count] [-onlyin directory] query
Key
query A string or query expression.
-0 Print an ASCII NUL character after each result path.
This is useful when used in conjunction with xargs -0.
-live Causes the mdfind command to provide live-updates to the
number of files matching the query. When an update causes the
query results to change the number of matches is updated.
The find can be cancelled by typing ctrl-C.
-count Output the total number of matches, instead of the path
to the matching items.
-onlyin dir
Limit the scope of the search to the directory specified.
-literal Force the provided query string to be taken as a literal
query string, without interpretation.
-interpret Force the provided query string to be interpreted as if the
user had typed the string into the Spotlight menu.
For example, the string "search" would produce the following
query string:
(* = search* cdw || kMDItemTextContent = search* cdw)
To get a list of the available attributes for use in constructing queries, see mdimport(1), particularly the -X switch.
Examples
Returns all files with any metadata attribute value matching the string "image":
$ mdfind image
Return all files that contain "Len Deighton" in the kMDItemAuthor metadata attribute:
$ mdfind "kMDItemAuthor == '*Len Deighton*'"
Return all files with any metadata attribute value matching the string "skateboard". The find continues to run after gathering the initial results, providing a count of the number of files that match the query.
$ mdfind -live skateboard
“The real voyage of discovery consists not in seeking new landscapes but in having new eyes” - Marcel Proust
Related:
find - Search for files that meet a desired criteria
mdimport - Import file hierarchies into the Spotlight datastore
mdutil - Manage Spotlight metadata store
mdls - List the metadata attributes for a specified file.