Post

Grep Cheatsheet

Recursively find matching file types

1
grep -Rl "my_file_name" .

Limit by file type

1
grep -R "search_text" --include="*.js" .
1
2
## Find Files by name

find /path/to/search -type f | grep “pattern”

1
2
3
4
5
## Find File containing text string.

```bash
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.