grep Commands
Search text with patterns.All grep pages
- grep -A -B -C: show lines before and after each matchgrep -A 3, -B 3 and -C 3 print lines after, before or around each match. How -n marks context lines, the -- separator between groups, and multi-file output.
- grep -r --include: search only certain file types recursivelygrep -rn --include='*.js' pattern . searches only matching file types recursively; --exclude-dir skips node_modules. Variations to list and count matches.
- grep -v: exclude lines that match a pattern (invert match)grep -v pattern prints only lines that do not match: drop comments, blank lines or debug messages, exclude several patterns, or remove one file's lines.
- grep multiple patterns: grep -e foo -e bar, grep -E 'foo|bar'Match any of several patterns with grep -e foo -e bar or grep -E 'foo|bar'. In basic regex | is literal unless escaped. -f reads a list; chain greps for AND.