Function: find-grep-dired

find-grep-dired is an autoloaded, interactive and byte-compiled function defined in find-dired.el.gz.

Signature

(find-grep-dired DIR REGEXP)

Documentation

Find files in DIR that contain matches for REGEXP and start Dired on output.

The command run (after changing into DIR) is

  find . \( -type f -exec grep-program find-grep-options \
    -e REGEXP {} \; \) -ls

where the first string in the value of the variable find-ls-option specifies what to use in place of "-ls" as the final argument.

View in manual

Probably introduced at or before Emacs version 19.1.

Key Bindings

Aliases

lookfor-dired (obsolete since 29.1) eshell/gf

Source Code

;; Defined in /usr/src/emacs/lisp/find-dired.el.gz
;;;###autoload
(defun find-grep-dired (dir regexp)
  "Find files in DIR that contain matches for REGEXP and start Dired on output.
The command run (after changing into DIR) is

  find . \\( -type f -exec `grep-program' `find-grep-options' \\
    -e REGEXP {} \\; \\) -ls

where the first string in the value of the variable `find-ls-option'
specifies what to use in place of \"-ls\" as the final argument."
  ;; Doc used to say "Thus ARG can also contain additional grep options."
  ;; i) Presumably ARG == REGEXP?
  ;; ii) No it can't have options, since it gets shell-quoted.
  (interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ")
  ;; find -exec doesn't allow shell i/o redirections in the command,
  ;; or we could use `grep -l >/dev/null'
  ;; We use -type f, not ! -type d, to avoid getting screwed
  ;; by FIFOs and devices.  I'm not sure what's best to do
  ;; about symlinks, so as far as I know this is not wrong.
  (find-dired dir
	      (concat "-type f -exec " grep-program " " find-grep-options " -e "
		      (shell-quote-argument regexp)
		      " "
		      (shell-quote-argument "{}")
		      " "
		      ;; Doesn't work with "+".
		      (shell-quote-argument ";"))))