Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Emacs how can I search a directory and all subdirectories for a filename?

share|improve this question

In dired, you can list all the subdirectories of the visited directory by moving to the first line and pressing C-u l and adding the R switch. You can then search the file name in the buffer, or mark files based on a regexp with % m.

On Linux, or Windows with Cygwin utilities, or other unix-like system with GNU find, a quick-and-dirty hack is M-x grep-find, and edit the command line to contain just the find part with a suitable format:

find -type f -name '*.foo' -printf '%p:0:\n'

On any system that has unix tools available, you can run the find command with M-! find. In the output buffer, you can use M-x ffap to visit the chosen file. You can also set up dired-x so that C-u C-x C-f can be used instead of M-x ffap.

share|improve this answer

You can open: */ for finding any files named in a direct subdirectory of the current one, or **/foo.barfor finding any files named recursively in subdirectories of the current one.

share|improve this answer
This doesn't work for me -- I suspect it requires some library that isn't loaded by default. – offby1 Oct 5 '12 at 20:27
It work here with stock Emacs (with emacs -q --no-site-file), I do know that this was not available with older Emacs, and it conflict with ido. – Rémi Oct 6 '12 at 11:30
You're right; it works for me, too. I never noticed that! – offby1 Oct 6 '12 at 17:44

In emacs 23, try M-x find-dired

share|improve this answer

You can use M-x find-name-dired. It will ask for a directory and a wildcard pattern, so you can enter something like *thing* and have all files with "thing" in the name listed in a dired buffer.

More here: (along with a snippet that lets you skip writing out the stars too).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .