Suppress normal output; instead print a count of matching lines for each input file. With the -v (--invert-match) option, count non-matching lines. (-c is specified by POSIX.)
Surround the matched (non-empty) strings, matching lines, context lines,
file names, line numbers, byte offsets, and separators (for fields and
groups of context lines) with escape sequences to display them in color
on the terminal.
The colors are defined by the environment variable
and default to ‘ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36’
for bold red matched text, magenta file names, green line numbers,
green byte offsets, cyan separators, and default terminal colors otherwise.
The deprecated environment variable
GREP_COLOR is still supported,
but its setting does not have priority;
it defaults to ‘01;31’ (bold red)
which only covers the color for matched text.
WHEN is ‘never’, ‘always’, or ‘auto’.
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning of each file stops on the first match.
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of each file stops on the first match. (-l is specified by POSIX.)
Stop reading a file after num matching lines.
If the input is standard input from a regular file,
and num matching lines are output,
grep ensures that the standard input is positioned
just after the last matching line before exiting,
regardless of the presence of trailing context lines.
This enables a calling process to resume a search.
For example, the following shell script makes use of it:
while grep -m 1 PATTERN do echo xxxx done < FILE
But the following probably will not work because a pipe is not a regular file:
# This probably will not work. cat FILE | while grep -m 1 PATTERN do echo xxxx done
grep stops after num matching lines,
it outputs any trailing context lines.
Since context does not include matching lines,
grep will stop when it encounters another matching line.
When the -c or --count option is also used,
grep does not output a count greater than num.
When the -v or --invert-match option is also used,
grep stops after outputting num non-matching lines.
Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line. Output lines use the same delimiters as input, and delimiters are null bytes if -z (--null-data) is also used (see Other Options).
Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option. (-q is specified by POSIX.)
Suppress error messages about nonexistent or unreadable files.
7th Edition Unix
grep did not conform to POSIX,
because it lacked -q
and its -s option behaved like
grep’s -q option.1
grep also lacked -q
but its -s option behaved like GNU
Portable shell scripts should avoid both
-q and -s and should redirect
standard and error output to /dev/null instead.
(-s is specified by POSIX.)
Of course, 7th Edition Unix predated POSIX by several years!