Manual / grep
grep(1)
| GREP(1) | General Commands Manual | GREP(1) |
NAME
grep - search files for a pattern
SYNOPSIS
grep [-cFilnqsvx] [-e expression] [-f pattern_file] expression [file...]
DESCRIPTION
Grep searches the input files (standard input default) for lines matching the regular expression. Normally, each line found is copied to the standard output.
- -v
- Select all lines but those matching.
- -c
- Print only a count of selected lines, per file.
- -n
- Precede each selected line by its line number, counted from 1.
- -i
- Match without regard to case.
- -l
- Print each file name once if it has a selected line.
- -q
- Print nothing; succeed as soon as a selected line is found.
- -s
- Suppress cannot-open messages, not error status.
- -x
- Require a whole-line match.
- -e expression
- 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.
- -f pattern_file
- 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.
- -F
- 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).
FILES
/usr/man/GREP this page
SEE ALSO
DIAGNOSTICS
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.
BUGS
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 |