OS Manuals

/usr/bin/grep

GNU grep implementation

From grep 3.12-r11 (os), captured 2026-11-05 by running grep --help (exit 0). permalink

Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
PATTERNS can contain multiple patterns separated by newlines.

Pattern selection and interpretation:
  -E, --extended-regexp     PATTERNS are extended regular expressions
  -F, --fixed-strings       PATTERNS are strings
  -G, --basic-regexp        PATTERNS are basic regular expressions
  -P, --perl-regexp         PATTERNS are Perl regular expressions
  -e, --regexp=PATTERNS     use PATTERNS for matching
  -f, --file=FILE           take PATTERNS from FILE
  -i, --ignore-case         ignore case distinctions in patterns and data
      --no-ignore-case      do not ignore case distinctions (default)
  -w, --word-regexp         match only whole words
  -x, --line-regexp         match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline

Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             display version information and exit
      --help                display this help text and exit

Output control:
  -m, --max-count=NUM       stop after NUM selected lines
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print file name with output lines
  -h, --no-filename         suppress the file name prefix on output
      --label=LABEL         use LABEL as the standard input file name prefix
  -o, --only-matching       show only nonempty parts of lines that match
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is 'binary', 'text', or 'without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is 'read', 'recurse', or 'skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is 'read' or 'skip'
  -r, --recursive           like --directories=recurse
  -R, --dereference-recursive  likewise, but follow all symlinks
      --include=GLOB        search only files that match GLOB (a file pattern)
      --exclude=GLOB        skip files that match GLOB
      --exclude-from=FILE   skip files that match any file pattern from FILE
      --exclude-dir=GLOB    skip directories that match GLOB
  -L, --files-without-match  print only names of FILEs with no selected lines
  -l, --files-with-matches  print only names of FILEs with selected lines
  -c, --count               print only a count of selected lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --group-separator=SEP  print SEP on line between matches with context
      --no-group-separator  do not print separator for matches with context
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is 'always', 'never', or 'auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS/Windows)

When FILE is '-', read standard input.  If no FILE is given, read standard
input, but with -r, recursively search the working directory instead.  With
fewer than two FILEs, assume -h.  Exit status is 0 if any line is selected,
1 otherwise; if any error occurs and -q is not given, the exit status is 2.

Report bugs to: bug-grep@gnu.org
GNU grep home page: <https://www.gnu.org/software/grep/>
General help using GNU software: <https://www.gnu.org/gethelp/>
Options (49)
OptionDescriptionSource
-E, --extended-regexpInterpret PATTERNS as extended regular expressions (EREs, see below).help + man
-F, --fixed-stringsInterpret PATTERNS as fixed strings, not regular expressions.help + man
-G, --basic-regexpInterpret PATTERNS as basic regular expressions (BREs, see below).help + man
-P, --perl-regexpInterpret PATTERNS as Perl-compatible regular expressions (PCREs).help + man
-e, --regexp PATTERNSUse PATTERNS as the patterns.help + man
-f, --file FILEObtain patterns from FILE, one per line.help + man
-i, --ignore-caseIgnore case distinctions in patterns and input data, so that characters that differ only in case match each other.help + man
--no-ignore-caseDo not ignore case distinctions in patterns and input data.help + man
-w, --word-regexpSelect only those lines containing matches that form whole words.help + man
-x, --line-regexpSelect only those matches that exactly match the whole line.help + man
-z, --null-dataTreat input and output data as sequences of lines, each terminated by a zero byte (the ASCII NUL character) instead of a newline.help + man
-s, --no-messagesSuppress error messages about nonexistent or unreadable files.help + man
-v, --invert-matchInvert the sense of matching, to select non-matching lines.help + man
-V, --versionOutput the version number of grep and exit.help + man
--helpOutput a usage message and exit.help + man
-m, --max-count NUMStop reading a file after NUM matching lines.help + man
-b, --byte-offsetPrint the 0-based byte offset within the input file before each line of output.help + man
-n, --line-numberPrefix each line of output with the 1-based line number within its input file.help + man
--line-bufferedUse line buffering on output.help + man
-H, --with-filenamePrint the file name for each match.help + man
-h, --no-filenameSuppress the prefixing of file names on output.help + man
--label LABELDisplay input actually coming from standard input as input coming from file LABEL.help + man
-o, --only-matchingPrint only the matched (non-empty) parts of a matching line, with each such part on a separate output line.help + man
-q, --quiet, --silentsuppress all normal outputhelp + man
--binary-files TYPEIf a file's data or metadata indicate that the file contains binary data, assume that the file is of type TYPE.help + man
-a, --textProcess a binary file as if it were text;help + man
-IProcess a binary file as if it did not contain matching data;help + man
-d, --directories ACTIONIf an input file is a directory, use ACTION to process it.help + man
-D, --devices ACTIONIf an input file is a device, FIFO or socket, use ACTION to process it.help + man
-r, --recursiveRead all files under each directory, recursively, following symbolic links only if they are on the command line.help + man
-R, --dereference-recursiveRead all files under each directory, recursively.help + man
--include GLOBSearch only files whose base name matches GLOB (using wildcard matching as described under --exclude).help + man
--exclude GLOBSkip any command-line file with a name suffix that matches the pattern GLOB, using wildcard matching;help + man
--exclude-from FILESkip files whose base name matches any of the file-name globs read from FILE (using wildcard matching as described under --exclude).help + man
--exclude-dir GLOBSkip any command-line directory with a name suffix that matches the pattern GLOB.help + man
-L, --files-without-matchprint only names of FILEs with no selected lineshelp + man
-l, --files-with-matchesprint only names of FILEs with selected lineshelp + man
-c, --countprint only a count of selected lines per FILEhelp + man
-T, --initial-tabMake sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal.help + man
-Z, --nullOutput a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.help + man
-B, --before-context NUMPrint NUM lines of leading context before matching lines.help + man
-A, --after-context NUMPrint NUM lines of trailing context after matching lines.help + man
-C, --context NUMPrint NUM lines of output context.help + man
-NUMsame as --context=NUMhelp
--group-separator SEPWhen -A, -B, or -C are in use, print SEP instead of -- between groups of lines.help + man
--no-group-separatorWhen -A, -B, or -C are in use, do not print a separator between groups of lines.help + man
--color WHENhelp
--colour WHENuse markers to highlight the matching strings;help
-U, --binarydo not strip CR characters at EOL (MSDOS/Windows)help + man
Exit status (3) from the manual page
0a line is selected
1no lines were selected
2an error occurred
Examples (1) from the manual page, untested

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.