Emacs: Search Text in Directory

By Xah Lee. Date: . Last updated: .

Find Text in a Directory (no need grep)

Emacs: Find Replace in Pure Elisp, xah-find.el

Find Text in a Directory (need grep)

Alt+x grep
List all matching text of all files in the current directory. (Emacs grep command calls the unix grep command. On Microsoft Windows, you need to install it.)
The current directory is usually the folder the current opend file is in. You can first call dired to a folder you want.
It will prompt you like this: grep --color -nH -e ▮. For example, if you give this input grep -nH -e "Cheshire" *html. If you want case insensitive search, add a -i in the grep option.
emacs grep 2014
emacs Alt+x grep output, showing list of files with matched text.

Find Text in Nested Directories (need grep)

Find text in directory and all subdirectories, you can call any of:

Alt+x rgrep
Search all files in current directory and subdirectory.
Alt+x lgrep
Search only some files of current dir by using a text pattern (regex) on file names first.
Alt+x grep-find
Use a combination of unix grep and find commands. Example prompt: find . -type f -print0 | xargs -0 -e grep -nH -e MySearchStr▮. (the exact prompt depends on your OS.)

Search Text from Dired (need grep)

Alt+x dired-do-find-regexp
Find all matches for REGEXP in marked files or the file under cursor. Requires the unix command find, xargs, grep.

Show Matched Files in Dired (need grep)

Alt+x find-dired
Run unix find command to list files and show them in dired. [see Emacs: File Manager, dired]

Emacs Find Replace

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Emacs Tutorial

Quick Start

Manage Windows



Find Replace




Rectangle Edit

Line Wrap


View Special File

Editing Brackets

Org Mode


Emacs Efficiency