Find Files in Emacs

Find-name-dired (based on wildcards not regular expressions, i.e. shell glob)
C-c f

e.g. john?smith

? equals single character
asterisk (*) equals character or no character

Find-dired (Based on unix find-command)

C-c F

https://www.reddit.com/r/emacs/comments/agvaa4/a_better_way_to_find_files_by_name_in_emacs/

eli-zaretskii (GNU Emacs maintainer) writes:

"Doing separate searches doesn't sound such a bad solution to me. If you want to do it in a single search, then use the following command:

M-x find-dired RET <directory> RET -name "john*camp" -o -name "camp*john" RET

This is not too complicated: -o is the OR operator, and you can use it several times."

Another example of my own:

e.g. -iname "magi" -not -iname "magi[tc]" -o -iname "wise*men"

To customize the format of the listings customize the variable find-ls-option. See Emacs Manual p. 351

My customizations to find:

-iname "avenant*philippa" -o -iname "philippa-avenant" -exec ls -ldh {} ";"

Find only directories
find-lisp-find-dired-subdirectories

find-lisp-find-dired (regexp)
Emulates a basic regexp find in elisp (very fast)

e.g. .\txt$ .*\.txt$

;; The Simple Way to Find Files by Name in Emacs

(global-set-key (kbd "C-c f") 'find-name-dired)

(global-set-key (kbd "C-c s") 'find-lisp-find-dired)

;; `find-name-dired' (requires the external `find' command)
;; Uses globbing patterns for matching file names:
;; `?' matches exactly one character, `*' matches zero or more characters

;; `find-lisp-find-dired' (requires no external app)
;; Uses Emacs regular expressions for matching file names
;; Especially useful for finding files with specific extensions
;; In this command, the case sensitivity of searches is determined by the variable `case-fold-search'
;; My "go to" command for file searching in Emacs

;; EXTRA
;; The `find-dired' command, based on the Unix find command
;; URL: https://www.reddit.com/r/emacs/comments/agvaa4/a_better_way_to_find_files_by_name_in_emacs/

;; Examples:
;; -name "*.txt" (extentions)
;; -type f -empty (empty files)
;; -size +1000M (files over a certain size)
;; -type f -iname "*aristotle*" (files with uncertain names)
;; -iname *john*camp* -o -iname *camp*john* (alternatives)

Return to Home