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:

  1. Navigate to the folder in the finder.

  2. Type your search of the content in the file you are searching for in the search bar on the top right of the folder.

  3. 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.

  4. 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.

  • I know about spotlight, but it doesn't seem to have a way to specify what you want to look for more precisely. also it doesn't seem to be looking in certain types of files which are text files but which have weird extensions. – Jason S Dec 1 '09 at 4:09
  • Read Spotlight 101: support.apple.com/kb/HT2531 – markratledge Dec 1 '09 at 4:15

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.


Using AppleScript (and do shell script to use Perl) it's possible to run a script to select all the files that match a regular expression. This can be combined with programs such as FastScripts and is actually documented and available for download by the developer on his blog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.