A recursive grep in a directory should be the simplest thing, but I haven't found the recipe to get it to work yet. I'm juggling between the following commands and am not sure which has the functionality buried within it:

  • helm-find-files: The problem is this is really bad at finding a directory recursively.
  • projectile-find-dir: This is great at finding the dir! However despite using helm complete you don't wind up in helm mode, so the C-u C-s command doesn't work here.
  • helm-find: gets the recursion right but targets files, not directories
  • helm-projectile-find-dir: Seems to be what I want.
  • 1
    I love ag and ag-mode for that, the silver searcher beats grep with one hand tied to its back :-), don't know how to make it projectile aware, though – Tom Regner Apr 22 '15 at 3:33
  • M-x projectile-ag maybe ? («projectile-prefix» A or «projectile-prefix» a – depending on the version) – Mekk Apr 22 '15 at 8:25
  • 2
    To the original poster: I do not quite understand what is your purpose. projectile-ack and projectile-ag are both great recursive greps within (whole) projectile project. Aren't they what you need? – Mekk Apr 22 '15 at 8:27

You have two ways:

  • Use helm-projectile-grep/ack/ag: You can search for everything starting from project root. Later if you want to save the search results, press F3 or press TAB to switch to action menu and select the 3rd action. To navigate hgrep buffer:

    • C-<down>: go to next match and open the match.
    • C-<up>: go to previous match and open the match.
    • M-<down>: go to next match without opening the match.
    • M-<up>: go to next match without opening the match.
    • C-o: open current match in other window.
    • RET: open current match in current window.
  • Use helm-projectile-find-dir (note the helm prefix; you must use proper Helm commands from helm-projectile package in general): narrow to a desired directory and press C-u C-s to recursively search in that directory. If you don't press C-u, it just searches in that directory without going deeper.

Hope that helps.

  • 1
    You have just enabled me to unlock a huge gain by informing me of this "TAB" action within a projectile search result. Thank you. Thank you, sir. – emish May 20 '16 at 17:36

A recursive grep in a directory should be the simplest thing

For a simple recursive grep inside current directory, just: M-x grep then, inside the minibuffer: Run grep (like this): grep -nHr "pattern". (notice the -r flag).

You may also be interested by rgrep:

rgrep is an interactive autoloaded compiled Lisp function in

(rgrep REGEXP &optional FILES DIR CONFIRM)

Recursively grep for REGEXP in FILES in directory tree rooted at DIR. The search is limited to file names matching shell pattern FILES. FILES may use abbreviations defined in grep-files-aliases', e.g. enteringch' is equivalent to `*.[ch]'.

  • That is not linked to projectile which it should be in the context. – RichieHH Dec 26 '19 at 13:00

In addition to the tools mentioned in the other answers, another cool function is find-grep-dired which creates a dired buffer containing all files matching a recursive grep pattern.

It just runs find . \( -type f -exec grep -q -e my-regular-expression \{\} \; \) -ls and displays the results in a dired buffer.


You could try helm-do-grep. Calling it with a prefix arg gives you a recursive grep, as explained in the Helm Wiki.

If you want to launch helm-do-grep recursively without starting helm-find-files, do:

C-u helm-command-prefix-key M-g s

NOTE: If you forget to hit C-u before M-g s you can do it after file selection.

You will be prompted for selecting in which category of files to search: Use the wilcard syntax like *.el for example (search in only .el files).

By default, the extension of the file at point is used when the cursor is on a filename. If the cursor is at root of a directory, all the filename extensions found in the directory and not matching grep-find-ignored-files are inserted into the prompt.

Try it like so:

C-u helm-command-prefix-key M-g s


This package has exactly what you are looking for:

The command's name is helm-do-ag.

  • Can I specify a set of folders where I could search always by default? – Emmanuel Goldstein Jan 15 at 9:49

helm-projectile-find-dir is probably the proper functionality. You can

  1. Find a directory as in projectile-find-dir
  2. But then you finish in Helm mode where you can run C-u C-s for a recursive search as desired.

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.