OS Manuals

/usr/bin/pcregrep

Perl-compatible regular expression library

From pcre 8.45-r12 (os), captured 2026-11-05 by running pcregrep --help (exit 0). permalink

Usage: pcregrep [OPTION]... [PATTERN] [FILE1 FILE2 ...]
Search for PATTERN in each FILE or standard input.
PATTERN must be present if neither -e nor -f is used.
"-" can be used as a file name to mean STDIN.
All files are read as plain files, without any interpretation.

Example: pcregrep -i 'hello.*world' menu.h main.c

Options:
      --                       terminate options
      --help                   display this help and exit
  -A, --after-context=number   set number of following context lines
  -a, --text                   treat binary files as text
  -B, --before-context=number  set number of prior context lines
      --binary-files=word      set treatment of binary files
      --buffer-size=number     set processing buffer size parameter
      --color=option           matched text color option
      --colour=option          matched text colour option
  -C, --context=number         set number of context lines, before & after
  -c, --count                  print only a count of matching lines per FILE
  -D, --devices=action         how to handle devices, FIFOs, and sockets
  -d, --directories=action     how to handle directories
  -e, --regex(p)=pattern       specify pattern (may be used more than once)
  -F, --fixed-strings          patterns are sets of newline-separated strings
  -f, --file=path              read patterns from file
      --file-list=path         read files to search from file
      --file-offsets           output file offsets, not text
  -H, --with-filename          force the prefixing filename on output
  -h, --no-filename            suppress the prefixing filename on output
  -I                           treat binary files as not matching (ignore)
  -i, --ignore-case            ignore case distinctions
      --no-jit                 do not use just-in-time compiler optimization
  -l, --files-with-matches     print only FILE names containing matches
  -L, --files-without-match    print only FILE names not containing matches
      --label=name             set name for standard input
      --line-buffered          use line buffering
      --line-offsets           output line numbers and offsets, not text
      --locale=locale          use the named locale
      --match-limit=number     set PCRE match limit option
      --recursion-limit=number set PCRE match recursion limit option
  -M, --multiline              run in multiline mode
  -N, --newline=type           set newline type (CR, LF, CRLF, ANYCRLF or ANY)
  -n, --line-number            print line number with output lines
  -o, --only-matching=n        show only the part of the line that matched
      --om-separator=text      set separator for multiple -o output
  -q, --quiet                  suppress output, just set return code
  -r, --recursive              recursively scan sub-directories
      --exclude=pattern        exclude matching files when recursing
      --include=pattern        include matching files when recursing
      --exclude-dir=pattern    exclude matching directories when recursing
      --include-dir=pattern    include matching directories when recursing
      --exclude-from=path      read exclude list from file
      --include-from=path      read include list from file
  -s, --no-messages            suppress error messages
  -u, --utf-8                  use UTF-8 mode
  -V, --version                print version information and exit
  -v, --invert-match           select non-matching lines
  -w, --word-regex(p)          force patterns to match only as words
  -x, --line-regex(p)          force patterns to match only whole lines

Numbers may be followed by K or M, e.g. --buffer-size=100K.
The default value for --buffer-size is 20480.
When reading patterns or file names from a file, trailing white
space is removed and blank lines are ignored.
The maximum size of any pattern is 8192 bytes.

With no FILEs, read standard input. If fewer than two FILEs given, assume -h.
Exit status is 0 if any matches, 1 if no matches, and 2 if trouble.
Options (49)
OptionDescriptionSource
--helpOutput a help message, giving brief details of the command options and file type support, and then exit.help + man
-A, --after-context numberOutput number lines of context after each matching line.help + man
-a, --textTreat binary files as text.help + man
-B, --before-context numberOutput number lines of context before each matching line.help + man
--binary-files wordSpecify how binary files are to be processed.help + man
--buffer-size numberSet the parameter that controls how much memory is used for buffering files that are being scanned.help + man
--color optionmatched text color optionhelp
--colour optionIf this option is given without any data, it is equivalent to "--colour=auto".help + man
-C, --context numberOutput number lines of context both before and after each matching line.help + man
-c, --countDo not output individual lines from the files that are being scanned;help + man
-D, --devices actionIf an input path is not a regular file or a directory, "action" specifies how it is to be processed.help + man
-d, --directories actionIf an input path is a directory, "action" specifies how it is to be processed.help + man
-e, --regex, --regexp patternspecify pattern (may be used more than once)help + man
-F, --fixed-stringsInterpret each data-matching pattern as a list of fixed strings, separated by newlines, instead of as a regular expression.help + man
-f, --file pathRead patterns from the file, one per line, and match them against each line of input.help + man
--file-list pathRead a list of files and/or directories that are to be scanned from the given file, one per line.help + man
--file-offsetsInstead of showing lines or parts of lines that match, show each match as an offset from the start of the file and a length, separated by a comma.help + man
-H, --with-filenameForce the inclusion of the filename at the start of output lines when searching a single file.help + man
-h, --no-filenameSuppress the output filenames when searching multiple files.help + man
-Itreat binary files as not matching (ignore)help + man
-i, --ignore-caseIgnore upper/lower case distinctions during comparisons.help + man
--no-jitIf the PCRE library is built with support for just-in-time compiling (which speeds up matching), pcregrep automatically makes use of this, unless it was explicitly disabled at build time.help + man
-l, --files-with-matchesInstead of outputting lines from the files, just output the names of the files containing lines that would have been output.help + man
-L, --files-without-matchInstead of outputting lines from the files, just output the names of the files that do not contain any lines that would have been output.help + man
--label nameThis option supplies a name to be used for the standard input when file names are being output.help + man
--line-bufferedWhen this option is given, input is read and processed line by line, and the output is flushed after each write.help + man
--line-offsetsInstead of showing lines or parts of lines that match, show each match as a line number, the offset from the start of the line, and a length.help + man
--locale localeThis option specifies a locale to be used for pattern matching.help + man
--match-limit numberProcessing some regular expression patterns can require a very large amount of memory, leading in some cases to a program crash if not enough is available.help + man
-M, --multilineAllow patterns to match more than one line.help + man
-N, --newline typeThe PCRE library supports five different conventions for indicating the ends of lines.help + man
-n, --line-numberPrecede each output line by its line number in the file, followed by a colon for matching lines or a hyphen for context lines.help + man
-o, --only-matching nShow only the part of the line that matched a pattern instead of the whole line.help + man
--om-separator textSpecify a separating string for multiple occurrences of -o.help + man
-q, --quietWork quietly, that is, display nothing except error messages.help + man
-r, --recursiveIf any given path is a directory, recursively scan the files it contains, taking note of any --include and --exclude settings.help + man
--exclude patternFiles (but not directories) whose names match the pattern are skipped without being processed.help + man
--include patternIf any --include patterns are specified, the only files that are processed are those that match one of the patterns (and do not match an --exclude pattern).help + man
--exclude-dir patternDirectories whose names match the pattern are skipped without being processed, whatever the setting of the --recursive option.help + man
--include-dir patternIf any --include-dir patterns are specified, the only directories that are processed are those that match one of the patterns (and do not match an --exclude-dir pattern).help + man
--exclude-from pathTreat each non-empty line of the file as the data for an --exclude option.help + man
--include-from pathTreat each non-empty line of the file as the data for an --include option.help + man
-s, --no-messagesSuppress error messages about non-existent or unreadable files.help + man
-u, --utf-8Operate in UTF-8 mode.help + man
-V, --versionWrite the version numbers of pcregrep and the PCRE library to the standard output and then exit.help + man
-v, --invert-matchInvert the sense of the match, so that lines which do not match any of the patterns are the ones that are found.help + man
-w, --word-regex, --word-regexpForce the patterns to match only whole words.help + man
-x, --line-regex, --line-regexpForce the patterns to be anchored (each must start matching at the beginning of a line) and in addition, require them to match entire lines.help + man
--recursion-limit numberSee --match-limit above. (in the manual page but not in --help)man
Exit status (2) from the manual page
0any matches were found
1no matches were found

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