This is a question coming from a former/current Windows user. If I'm looking at a Finder window in a particular directory, how can I search for files with names matching a particular pattern (e.g. "p*.php") that contain a particular string of text?
You can't do this from the spotlight icon in the menu bar. But you can do it with spotlight:
Navigate to the folder in the finder.
Type your search of the content in the file you are searching for in the search bar on the top right of the folder.
There is a line above the results that says:
Search: This Mac "Your Folder Name"Click on the name of your folder to restrict the search to the folder instead of the whole computer, which is what the default selection "This Mac" does.
Then click the gear icon, choose show search criteria, and narrow down your search. For example you can add "Name ends with .php" and then click the plus to add another criteria. You could then add "Name begins with p"
Edit: I just grabbed a php file and searched for this string
array_push($songs,$song) and it will not find the file, but if I only search up to the comma (ie
array_push($songs ) spotlight does find the file!
I found this article which explains how to add php as a supported file type for spotlight which should fix the weird result I experienced above. I believe without this change spotlight treats the file as rtf only so some php elements (punctuation especially) will make the search fail. The command to edit the required file is:
sudo nano /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist
You'll want to reindex after this change as the article mentions. It also mentions the more proper way to do this is to install the developer tools.
You can then use the method I described above to restrict your search to a specific folder or file type.
One simple way is Spotlight, in the upper right hand corner of the file window or the desktop screen; that's plain text for file names and strings. Grep is possible with Terminal and *unix commands (Terminal is in Applications/Utilities/). There's Aqua Command-Line Tools, though it looks old.
Some programmer's text editors offer a grep-like feature for searching for a regular expression across multiple files; many (many) moons ago BBEdit had this feature (and probably still does; I just haven't used it for years). I wouldn't be surprised to find that other tools targeted at the developer market also have similar features.
Both Spotlight and the Finder are an attempt at reaching out to the sort of people who keep the "For Dummies" line of books on shelves, and as such, are not capable of parsing regular expressions or anything else particularly fancy. A lot of people like PathFinder as a replacement but I find it more trouble than it's worth since the Finder will keep launching itself no matter what you do.