Skip to main content
Kill -9 Club
Sign in

grep

TextPackage: grep

Searches for a pattern in files or in what is piped to it, and returns the line — or with -q only an exit status, which makes it a test in a script. The pattern is a regular expression unless -F.

What its options do in the lessons

From the same glossary the lessons render under their commands, so the two cannot disagree.

grep -q
Prints nothing: the answer is the exit status, 0 if the pattern was found and 1 if it was not. This is the form that makes grep usable in an if, and the only one that means anything in a script.
grep -F
Takes the pattern literally instead of reading it as a regular expression. The . in an address or a version number then stops matching any character at all.
grep -x
Requires the whole line to match, not part of one. Without it, looking for max_workers = 4 also finds # max_workers = 4 — a commented-out setting the script will take for an applied one.
grep -i
Ignores case.
grep -n
Prefixes each result with its line number.
grep -c
Counts matching lines instead of printing them. Answers the question of how many, without scrolling a file of several thousand lines.
grep -E
Extended regular expressions: |, +, ? and parentheses without escaping them.
grep -C
Prints N lines of context around each match.
grep -r
Descends into the subdirectories of the given path. This searches file *contents*, where find -name searches their names.

Lessons that teach it