I've read, for instance here, that one could just run M-x grep to interface with the underlying shell and just run a simple grep command. I suspect something is wrong in the setup because this simple command does not work. Here's what I can see:

enter image description here

The command I type after M-x grep is

grep 'Cell' input.scs

It can be seen in the above screenshot right above the (garbled) shell prompt.

I don't know if that's a sign but it looks like the codes used to format the shell prompt are not totally understood by the *grep* buffer, but besides that, the process seems to stay in the "compiling" state forever, never returning any hit.

On the other hand, the very same command grep 'Cell' input.scs (you can see above the prompt) does work fine in a shell inside the directory this file is in.

Running emacs -nw input.scs returns basically the same output. Here I have used the command:

grep -A1 'Cell' input.scs

enter image description here

If I run emacs -Q input.scs to avoid loading of init.el, I still get the same result:

enter image description here

What can be possibly going wrong there?

  • You don't show the grep command you used with M-x grep. And say what grep you're using. And say whether you're using Emacs in terminal mode. Do you see this when you start Emacs using emacs -Q (no init file)? If not, bisect your init file to find the culprit. If yes, normally (with most greps) it just works out of the box, and even if you try to grep binary files grep just tells you that a file is binary - it doesn't vomit terminal escape chars or binary data.
    – Drew
    Commented Feb 14, 2023 at 2:40
  • Also, please post only one question per post. I think your question is really about getting the Emacs grep command to work, and that has nothing to do with Dired. Please edit to just ask about your M-x grep problem.
    – Drew
    Commented Feb 14, 2023 at 2:42
  • Thank you for your comments @Drew, I will implement your suggestions. The grep command I have written explicitly and it is also visible in the screenshot, btw. Commented Feb 14, 2023 at 10:06
  • Regarding the color codes, I think it might require running ansi-color-apply-on-region, which is not an interactive command or other related ansi-color-* functions.
    – Arktik
    Commented Mar 16, 2023 at 16:09
  • If it works in the shell within the file's directory, could it be that the default directory string in the GUI Emacs causing the problem? We can't see it. Also, is it on a remote computer?
    – Arktik
    Commented Mar 16, 2023 at 16:18

1 Answer 1


press A to run dired-do-find-regexp in dired buffer

from its docstring:

Find all matches for REGEXP in all marked files.
If no files are marked, use the file under point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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