Skip to main content

find all files containing specific text / pattern

List the files containing pattern

grep -rl ['PATH'] -e 'PATTERN'

in current path:

grep -rl ./ -e 'PATTERN'

where

  • -r recursive lazy

  • -l (lower-case L) show the file name, not the result itself

more options

  • -n show line number

  • -R recursive greedy

  • -i stands for ignore case

  • -w stands for match the whole word

  • -o print only the matched (non-empty) parts of a matching line, with each such part on a separate output line

  • --color=auto mark up the matching text

  • --include Example: --include=\*.{c,h} will only search through those files which have .c or .h extensions

  • --exclude Example: --exclude=*.o will exclude searching all the files ending with .o extension

  • --exclude-dir Example: --exclude-dir={dir1,dir2,*.dst} will exclude the dirs dir1/, dir2/ and all of them matching *.dst/

PATTERN is normally case sensitiv
man page: http://man7.org/linux/man-pages/man1/grep.1.html