OS Manuals

/usr/bin/pcre2grep

perl-compatible regular expression library

From pcre2 10.49-r3 (os), captured 2026-11-05 by running pcre2grep --help (exit 0). permalink

Usage: pcre2grep [OPTION]... [PATTERN] [FILE1 FILE2 ...]
Search for PATTERN in each FILE or standard input.
PATTERN must be present if neither -e nor -f is used.
All callout scripts in patterns are supported.
"-" can be used as a file name to mean STDIN.
Files whose names end in .gz are read using zlib.
Other files and the standard input are read as plain files.

Example: pcre2grep -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 starting size
      --max-buffer-size=number set processing buffer maximum size
      --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
      --posix-digit            \d always matches [0-9], even in UTF/UCP mode
  -E, --case-restrict          restrict case matching (no mix ASCII/non-ASCII)
  -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
      --posix-pattern-file     use POSIX semantics for pattern files
      --file-list=path         read files to search from file
      --file-offsets           output file offsets, not text
      --group-separator=text   set separator between groups of lines
  -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
  -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
      --heap-limit=number      set PCRE2 heap limit option (kibibytes)
      --match-limit=number     set PCRE2 match limit option
      --depth-limit=number     set PCRE2 depth limit option
      --recursion-limit=number obsolete synonym for depth-limit
  -M, --multiline              run in multiline mode
  -m, --max-count=number       stop after <number> matched lines
  -N, --newline=type           set newline type (CR, LF, CRLF, ANYCRLF, ANY, or NUL)
  -n, --line-number            print line number with output lines
      --no-jit                 do not use just-in-time compiler optimization
      --no-group-separator     suppress separators between groups of lines
  -O, --output=text            show only this text (possibly expanded)
  -o, --only-matching=n        show only the part of the line that matched
      --om-separator=text      set separator for multiple -o output
      --om-capture=n           set capture count for --only-matching
  -P, --no-ucp                 do not enable UCP mode with Unicode
  -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
  -t, --total-count            print total count of matching lines
  -u, --utf                    use UTF/Unicode
  -U, --utf-allow-invalid      use UTF/Unicode, allow for invalid code units
  -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
      --allow-lookaround-bsk   allow \K in lookarounds
  -Z, --null                   output 0 byte after file names

Numbers may be followed by K or M, e.g. --max-buffer-size=100K.
The default value for --buffer-size is 20480.
The default value for --max-buffer-size is 1048576.
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 (65)
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 up to number lines of context after each matching line.help + man
-a, --textTreat binary files as text.help + man
-B, --before-context numberOutput up to 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 obtained at the start of processing 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 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
--posix-digit\d always matches [0-9], even in UTF/UCP modehelp
-E, --case-restrictWhen case distinctions are being ignored in Unicode mode, two ASCII letters (K and S) will by default match Unicode characters U+212A (Kelvin sign) and U+017F (long S) respectively, as well as their…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.help + man
--posix-pattern-fileWhen patterns are provided with the -f option, do not trim trailing spaces or ignore empty lines in a similar way than other grep tools.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
--group-separator textOutput this text string instead of two hyphens between groups of lines when -A, -B, or -C is in use.help + man
-H, --with-filenameForce the inclusion of the file name at the start of output lines when searching a single file.help + man
-h, --no-filenameSuppress the output file names when searching multiple files.help + man
-Itreat binary files as not matching (ignore)help + man
-i, --ignore-caseIgnore upper/lower case distinctions when pattern matching.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, non-compressed 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
--heap-limit numberset PCRE2 heap limit option (kibibytes)help + man
--match-limit numberProcessing some regular expression patterns may take a very long time to search for all possible matching strings.help + man
--depth-limit numberset PCRE2 depth limit optionhelp + man
-M, --multilineAllow patterns to match more than one line.help + man
-m, --max-count numberStop processing after finding number matching lines, or non-matching lines if -v is also set.help + man
-N, --newline typeSix different conventions for indicating the ends of lines in scanned files are supported.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
--no-jitIf the PCRE2 library is built with support for just-in-time compiling (which speeds up matching), pcre2grep automatically makes use of this, unless it was explicitly disabled at build time.help + man
--no-group-separatorDo not output a separator between groups of lines when -A, -B, or -C is in use.help + man
-O, --output textWhen there is a match, instead of outputting the line that matched, output just the text specified in this option, followed by an operating-system standard newline.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
--om-capture nSet the number of capturing parentheses that can be accessed by -o.help + man
-P, --no-ucpStarting from release 10.43, when UTF/Unicode mode is specified with -u or -U, the PCRE2_UCP option is used by default.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 whose names 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 whose names 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
-t, --total-countThis option is useful when scanning more than one file.help + man
-u, --utfOperate in UTF/Unicode mode.help + man
-U, --utf-allow-invalidAs --utf, but in addition subject lines may contain invalid UTF-8 code unit sequences.help + man
-V, --versionWrite the version numbers of pcre2grep and the PCRE2 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 only to match "words".help + man
-x, --line-regex, --line-regexpForce the patterns to start matching only at the beginnings of lines, and in addition, require them to match entire lines.help + man
--allow-lookaround-bskPCRE2 now forbids the use of K in lookarounds by default, in line with Perl.help + man
-Z, --nullTerminate files names in the regular output with a zero byte (the NUL character) instead of what would normally appear.help + man
--max-buffer-size numberThis limits the expansion of the processing buffer, whose initial size can be set by --buffer-size. (in the manual page but not in --help)man
--recursion-limit numberThis is an obsolete synonym for --depth-limit. (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.