maux
Star on GitHub Buy me a coffee

Manual / grep

grep(1)

GREP(1) General Commands Manual GREP(1)

grep - search files for a pattern

grep [-cFilnqsvx] [-e expression] [-f pattern_file] expression [file...]

Grep searches the input files (standard input default) for lines matching the regular expression. Normally, each line found is copied to the standard output.

Select all lines but those matching.
Print only a count of selected lines, per file.
Precede each selected line by its line number, counted from 1.
Match without regard to case.
Print each file name once if it has a selected line.
Print nothing; succeed as soon as a selected line is found.
Suppress cannot-open messages, not error status.
Require a whole-line match.
Supply a pattern explicitly; necessary if it begins with -. May be given more than once: a line is selected if it matches any of the patterns.
Read patterns from the file, one to a line, and add them to the set. An empty file supplies the null expression, which matches every line.
Treat each pattern as a fixed string rather than a regular expression.

With more than one input file, line and count output is prefixed by the file name. Line numbering restarts for each file. Care should be taken with characters meaningful to the shell; it is generally necessary to enclose the entire expression in quotes. For example:

grep -n '^START' source

The matcher is the same basic regular-expression engine used by ed(1).

/usr/man/GREP this page

ed(1), sed(1), sh(1), licenses(1)

Exit status is 0 if a line was selected, 1 if none was selected, 2 for usage or input-open errors. With -q a selected line returns 0 even after an earlier open error.

Only one pattern is supported: repeated -e, -f, -E and -F are refused. Lines are truncated to 255 bytes before matching. A final unterminated line is printed with a newline.

September 19, 2026 maux