Post

Grep Cheatsheet

Find Files by name

1
find /path/to/search -type f | grep "pattern"

Find File containing text string.

1
grep -rl "string" /path

find file containing text string in specific file type.

1
grep -r "example" *.txt

flags

-r (or --recursive)

Option is used to traverse also all sub-directories of /path, whereas

-l (or --files-with-matches)

option is used to only print filenames of matching files, and not the matching lines (this could also improve the speed, given that grep stop reading a file at first match with this option).

older gist

https://askubuntu.com/questions/55325/how-to-use-grep-command-to-find-text-including-subdirectories

find a string recursively

-r (or –recursive) option is used to traverse also all sub-directories of /path, whereas -l (or –files-with-matches) option is used to only print filenames of matching files, and not the matching lines (this could also improve the speed, given that grep stop reading a file at first match with this option).

grep -rl “string” /path

This post is licensed under CC BY 4.0 by the author.