How can I Spotlight search exclusively in `.txt` files in `~/.` on my disk?Ld uplA23% 5 d3f aXt Bj5liuFf x Y erv xBWJj
I was talking to Mr. Ramanujan at his desk when he gave me his cell phone number.
I recall I had a text editor open and I wrote the number in a file. Normally I store such details in ~/phone-numbers.txt, but that time I seem to have inadvertently written in another file.
No worries. I use Spotlight Search to search for Ramanujan, but it produces irrelevant search results of the famed mathematician, on and off my computer, especially off.
How can I search for Ramanujan solely in .txt files in files rooted at ~/.?
2 Answers
In terminal app using the command line, this is easy to do.
mdfind -onlyin ~ Ramanujan|grep txt
You could make a complex query and get rid of the pipe to grep, but the above should work very quickly. You could probably assemble a finder search as well with about 12 clicks if you couldn’t use the command line tools.
i don't know how to select which files Spotlight searches if it does search inside of files. A possible workaround is to use the free app Easyfind available from the app store. An image of the EasyFind window is shown below.

By clicking on the Settings button on the top left you can open the sidebar shown on the left. This is where you'll check which files to search the contents of. I've clecked the files containing txt, among other extensions, in the files name.