One of the classic Unix idioms is to search all files in a file hierarchy for some regular expression with a find/grep pipeline. For example, to search the lisp
directory and all of its subdirectories for file containing the mapcar
function, one could use
find ~/lisp -name "*.lisp" -exec grep -H mapcar {} \;
That pipeline finds every .lisp
file in the hierarchy and runs grep
on it looking for mapcar
.
I, at least, don’t do this type of thing very much anymore because there are so many easier ways of doing so, especially from within Emacs.
Nonetheless, it’s still possible to usefully combine find
and grep
from within Emacs to build a Dired buffer of all the files that contain the matching regex. This tweet by
Mickey tells you how:
You can combine the utils `grep’ with `find’ in #emacs with:
M-x find-grep-dired
Pick a directory and a pattern and you’ll get a dired listing of the matching files.
You can use the dired listing like you would any other dired buffer.
— Mickey Petersen (@mickeynp) January 19, 2022
There’s a bit more to the command so you should take a look at the on-line documentation if you have a use for it.