Searching multiple files with rgrep

Use M-x rgrep to search for a string in multiple files. You will be prompted for a string, the files to search and the directory to start the search. So, for example, to search for the word “emacs” in all .txt files in my documents directory, I might use M-x rgrep and then answer emacs, *.txt, and ~/docs/.

rgrep will open a new buffer containing the results. The nice thing is that clicking on one of the matches will open that file in emacs and take you right to the matching line.

Note that rgrep is recursive and so will also search all directories below the one specified. For more control, try M-x grep and M-x grep-find.