Notice the EXCLUSIONS list? You can add to that with the System
Preferences tool, but this is where it is actually stored. However,
as we'll see in a moment, this is NOT all that Spotlight (and mdfind)
ignores. You need to be aware of that when using mdfind.
For the simplest use, just do "mdfind whatever". Can you use
that in a script? Why not?
I put the string "fogpr1" in a file, and then copied it to
a few different names. Using "grep" finds all of them, but
"mdfind" does not:
$ grep -l fogpr1 *
$ mdfind fogpr1
Spotlight and mdfind also ignore "." files, even if you have told Finder
not to ignore them:
$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder
mdfind is a little strange with regard to "."'s in other ways: a nice
little option is (for example) to say "mdfind -onlyin /tmp foo", which would
search for foo but only in /tmp. You would naturally expect to be able to
say "mdfind -onlyin . foo", but that won't work. Use "mdfind -onlyin `pwd` foo"