<-- back

find-grep-dired: Filter files based on content


We all need to search in files sometimes, right?

I usually do it using grep -ri 'search term' . in the terminal (often in vterm-mode) and then I either open the file(s) in Emacs or in any other program.

But Emacs has better solution to it.


There is M-x find-grep-dired already built-in to Emacs. If you call it from Dired buffer it will auto-complete the current folder and then you just need to enter the search term.

Cool thing is that result of this function is just filtered Dired buffer which means you can perform regular Dired operations on the found files (delete them, move to another folder, etc).
This especially come in handy if you have (setq dired-dwim-target t) and another Dired buffer opened in split so you can quickly move files between splits (Far/Total Commander style).


M-x find-grep-dired is as quick as grep is.
According to this function’s help page you can change grep-program variable if you want to use rg, ag or whatever…
CAUTION: It’s pretty possible grep-program may be used by other Emacs functions that may expect grep-specific output.

Feel free to contact me for feedback or questions. Find my contacts on About page.