Spotlight can be powerful and fast, but lacks some precise control over the results. Typically you get far more results than you would ever need. The command-line interface unlocks more advanced functionality and you can also integrate it into your scripts.
The core command is “mdfind” and you could do “man mdfind” to see all the possibilties. However, here are a series of examples.
# Find every file that contains parakeet in the contents.
# Restrict the search to a folder and ites subfolders (NOTE: Must be full path)
mdfind parakeet -onlyin /Users/admin/Pictures
# Display current matches and provide a live update when the number of matches changes. Great for testing you command but also to see live updates of things like a log file being created by your script.
mdfind parakeet -onlyin /Users/admin/Pictures -live
# Just display the live updating count. Less verbose and if… READ THE REST