Apple - Searching by file name (as opposed to name and contents) in Lion

  1. Open a finder window
  2. Open the folder you wish to search in
  3. Click in the search box
  4. Type the text you want to find
  5. A dropdown should appear like the one in the image below which allows you to select the 'Filename contains' option

Finder window

If you've already run the search and want to alter the search to only look for files with your search term in the filename, you can click the '+' button just beneath the search box and change the search type from there. See screenshots below:

Finder window 2

Finder window 3

Mike Scott has nice suggestions from the comments that are worth incorporating here to use the name: selector in spotlight.

You can prefix your search with name: as shown below
Finder window 4

This results in a window which you can select 'Filename' or 'Everything' from if you click the button labelled 'name' in the search box as shown below:
Finder window 5


Search using the name: selector

name:index.html in spotlight

I've also become a big fan of the Found app. It's currently free on the app store and lightning fast (seems faster than LaunchBar to me - and that's saying a lot as it's a speed demon).


Another way would be to use the Terminal and the mdfind command-line utility. Add this function to your ~/.bash_profile (or any other shell config file you might use):

spot() {
  mdfind "kMDItemFSName=='*$@*'cd";
}

You can then use the spot function on the command-line:

spot foo bar

This will search for all files and directories containing the arguments you passed to spot in their name.

Note that cd in the above function is a modifier, making the search case-insensitive (c) and ignoring diacrtical marks (d). For more info about querying, see this document.