Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to search for keyword, says 'action', in a bunch of files in my Windows PC with Emacs.

It is partly because I want to learn more advanced features of emacs. It is also because the Windows PC is locked down by company policy. I cannot install useful applications like cygwin at will.

So I tried this command: M-x rgrep

It throws the following error message:

*- mode: grep; default-directory: "c:/Users/me/Desktop/Project" -*-
Grep started at Wed Oct 16 18:37:43

find . -type d "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o -path "*/MCVS" -o -path "*/.svn" -o -path "*/.git" -o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path "*/_darcs" -o -path "*/{arch}" ")" -prune -o "(" -name ".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak" -o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o -name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name "*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name "*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name "*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name "*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name "*.x86f" -o -name "*.sparcf" -o -name "*.dfsl" -o -name "*.pfsl" -o -name "*.d64fsl" -o -name "*.p64fsl" -o -name "*.lx64fsl" -o -name "*.lx32fsl" -o -name "*.dx64fsl" -o -name "*.dx32fsl" -o -name "*.fx64fsl" -o -name "*.fx32fsl" -o -name "*.sx64fsl" -o -name "*.sx32fsl" -o -name "*.wx64fsl" -o -name "*.wx32fsl" -o -name "*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name "*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name "*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name "*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name "*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name "*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune -o  -type f "(" -iname "*.sh" ")" -exec grep -i -n "action" {} NUL ";"
FIND: Parameter format not correct

Grep exited abnormally with code 2 at Wed Oct 16 18:37:44

I believe rgrep tried to spwan a process and called 'FIND' with all the parameters. However, since it is a Windows, the default Find executable simply does not know how to handle.

What is the better way to search for a keyword in multiple files in Emacs on Windows platform, without any dependency on external programs?

Emacs version: 24.2.1

share|improve this question
add comment

2 Answers

Open the directory where you want to search in dired-mode. Then mark all the files you want to search and finally do M-x dired-do-search RET keyword RET.

This will search the marked files for the keyword.

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Ramhound Oct 16 '13 at 17:21
    
Yes, it does answer the question. The only thing it does not do is search files in subdirectories, and sub-subdirectories, etc. recursively. Yes, rgrep does search such descendent directories, but @Dror's answer responds to the OP request to search a "bunch of file": A (dired-do-search) is a good answer. An even better answer, along the same lines, is M-s a C-s (dired-do-isearch). –  Drew Nov 3 '13 at 23:33
    
You could also hit i when the point is on a subdirectory, and this will it to the list in the same buffer. –  Dror Nov 4 '13 at 7:40
add comment
  1. If you use Dired+ and Icicles then you can search all marked files in a Dired buffer, including files marked in marked subdirs, and so on, recursively.

    Icicles search is a different kind of incremental search. You define search contexts, which are the parts of your text to be searched. You define the contexts by providing a regexp that they match. In a simple case of rgrep-like behavior, the contexts are just individual text lines, and the context-defining regexp is thus .* (match anything except a newline char).

    Here is an overview of Icicles search (and replace) behavior.

    If you have loaded both Icicles and Dired+, then the command to search all marked files in and below the current Dired buffer is on key M-s M-s m, and it is in the Dired mode menu bar as Multiple > Marked Here and Below > Icicles >Icicles Search (and Replace).

  2. If you use only Dired+ and not also Icicles, you can still incrementally search all of the files marked in the current Dired directory and all subdirectories (recursively). In this case, search uses ordinary Emacs Isearch. In Dired mode, the keys for this are M-+ M-s a C-s (string search, command diredp-do-isearch-recursive) and M-+ M-s a C-M-s (regexp search, command diredp-do-isearch-regexp-recursive). There is also the non-incremental version, command diredp-do-search-recursive, which is bound to M-+ A. (There are also keys/commands for query-replacing the marked files in and below the current Dired directory.)

  3. If you have Dired+ and Icicles and you are interested only in finding which of a given set of files contain a given keyword, that is, you are not searching for occurrences of that keyword but only want to know whether it is present, then you can use M-+ C-F (command icicle-visit-marked-file-of-content-recursive, menu Multiple > Marked Here and Below > Icicles > Open File of Content).

  4. A final word about the handling of files marked "here and below": you can mark a subdirectory and not mark any of its files, to have the same effect as marking each of its files. See Dired+ for more info.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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