grep Flags & Options
Search text with patterns.All grep pages
- grep -F: search for a literal string, not a regexgrep -F searches for a literal string, so dots, brackets and dollar signs lose their regex meaning. Search lists of IDs with -F -f, and the quoting pitfalls.
- grep -o: print only the matching part of each linegrep -o prints only the text that matched, one match per line, not the whole line. Count matches with wc -l, extract IDs from logs, avoid empty-match pitfalls.
- grep -r --exclude-dir=node_modules: skip directories in a recursive searchgrep --exclude-dir=DIR skips directories such as node_modules or .git during grep -r. Repeat it or use braces for several names; it matches base names only.
- grep -w: match whole words onlygrep -w matches a pattern only as a whole word, so cat no longer matches catalog. Which characters count as word characters, -w vs -x, and word boundaries.