{
    "mode": "info",
    "parameter": "egrep",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/egrep/json",
    "generated": "2026-07-29T01:25:31Z",
    "synopsis": "grep [OPTION...] PATTERNS [FILE...]\ngrep [OPTION...] -e PATTERNS ... [FILE...]\ngrep [OPTION...] -f PATTERNFILE ... [FILE...]",
    "sections": {
        "NAME": {
            "content": "grep, egrep, fgrep, rgrep - print lines that match patterns\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "grep [OPTION...] PATTERNS [FILE...]\ngrep [OPTION...] -e PATTERNS ... [FILE...]\ngrep [OPTION...] -f PATTERNFILE ... [FILE...]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "grep  searches  for  PATTERNS  in  each  FILE.  PATTERNS is one or more\npatterns separated by newline characters, and  grep  prints  each  line\nthat  matches a pattern.  Typically PATTERNS should be quoted when grep\nis used in a shell command.\n\nA FILE of \"-\"  stands  for  standard  input.   If  no  FILE  is  given,\nrecursive  searches  examine  the  working  directory, and nonrecursive\nsearches read standard input.\n\nIn addition, the variant programs egrep, fgrep and rgrep are  the  same\nas  grep -E,  grep -F,  and  grep -r, respectively.  These variants are\ndeprecated, but are provided for backward compatibility.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Generic Program Information\n--help Output a usage message and exit.\n",
            "subsections": [
                {
                    "name": "-V, --version",
                    "content": "Output the version number of grep and exit.\n\nPattern Syntax",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "-E, --extended-regexp",
                    "content": "Interpret PATTERNS as extended regular  expressions  (EREs,  see\nbelow).\n",
                    "flag": "-E",
                    "long": "--extended-regexp"
                },
                {
                    "name": "-F, --fixed-strings",
                    "content": "Interpret PATTERNS as fixed strings, not regular expressions.\n",
                    "flag": "-F",
                    "long": "--fixed-strings"
                },
                {
                    "name": "-G, --basic-regexp",
                    "content": "Interpret  PATTERNS  as  basic  regular  expressions  (BREs, see\nbelow).  This is the default.\n",
                    "flag": "-G",
                    "long": "--basic-regexp"
                },
                {
                    "name": "-P, --perl-regexp",
                    "content": "Interpret I<PATTERNS>  as  Perl-compatible  regular  expressions\n(PCREs).   This option is experimental when combined with the -z\n(--null-data) option, and grep  -P  may  warn  of  unimplemented\nfeatures.\n\nMatching Control\n-e PATTERNS, --regexp=PATTERNS\nUse  PATTERNS  as the patterns.  If this option is used multiple\ntimes or is combined with the -f (--file) option, search for all\npatterns  given.   This  option can be used to protect a pattern\nbeginning with \"-\".\n\n-f FILE, --file=FILE\nObtain patterns from FILE, one per line.  If this option is used\nmultiple  times  or  is  combined with the -e (--regexp) option,\nsearch for all patterns given.  The  empty  file  contains  zero\npatterns, and therefore matches nothing.\n",
                    "flag": "-P",
                    "long": "--perl-regexp"
                },
                {
                    "name": "-i, --ignore-case",
                    "content": "Ignore  case  distinctions  in  patterns and input data, so that\ncharacters that differ only in case match each other.\n",
                    "flag": "-i",
                    "long": "--ignore-case"
                },
                {
                    "name": "--no-ignore-case",
                    "content": "Do not ignore case distinctions  in  patterns  and  input  data.\nThis is the default.  This option is useful for passing to shell\nscripts that already use -i, to cancel its effects  because  the\ntwo options override each other.\n",
                    "long": "--no-ignore-case"
                },
                {
                    "name": "-v, --invert-match",
                    "content": "Invert the sense of matching, to select non-matching lines.\n",
                    "flag": "-v",
                    "long": "--invert-match"
                },
                {
                    "name": "-w, --word-regexp",
                    "content": "Select  only  those  lines  containing  matches  that form whole\nwords.  The test is that the matching substring must  either  be\nat  the  beginning  of  the  line,  or  preceded  by  a non-word\nconstituent character.  Similarly, it must be either at the  end\nof  the  line  or  followed by a non-word constituent character.\nWord-constituent  characters  are  letters,  digits,   and   the\nunderscore.  This option has no effect if -x is also specified.\n",
                    "flag": "-w",
                    "long": "--word-regexp"
                },
                {
                    "name": "-x, --line-regexp",
                    "content": "Select  only  those  matches  that exactly match the whole line.\nFor a regular expression pattern, this  is  like  parenthesizing\nthe pattern and then surrounding it with ^ and $.\n\n-y     Obsolete synonym for -i.\n\nGeneral Output Control",
                    "flag": "-x",
                    "long": "--line-regexp"
                },
                {
                    "name": "-c, --count",
                    "content": "Suppress  normal output; instead print a count of matching lines\nfor each input file.  With the -v,  --invert-match  option  (see\nbelow), count non-matching lines.\n",
                    "flag": "-c",
                    "long": "--count"
                },
                {
                    "name": "--color[=WHEN], --colour[=WHEN]",
                    "content": "Surround   the  matched  (non-empty)  strings,  matching  lines,\ncontext lines, file  names,  line  numbers,  byte  offsets,  and\nseparators  (for fields and groups of context lines) with escape\nsequences to display them in color on the terminal.  The  colors\nare  defined  by  the  environment  variable  GREPCOLORS.   The\ndeprecated environment variable GREPCOLOR is  still  supported,\nbut  its setting does not have priority.  WHEN is never, always,\nor auto.\n"
                },
                {
                    "name": "-L, --files-without-match",
                    "content": "Suppress normal output; instead print the  name  of  each  input\nfile from which no output would normally have been printed.\n",
                    "flag": "-L",
                    "long": "--files-without-match"
                },
                {
                    "name": "-l, --files-with-matches",
                    "content": "Suppress  normal  output;  instead  print the name of each input\nfile  from  which  output  would  normally  have  been  printed.\nScanning each input file stops upon first match.\n\n-m NUM, --max-count=NUM\nStop  reading  a file after NUM matching lines.  If the input is\nstandard input from a regular file, and NUM matching  lines  are\noutput,  grep  ensures  that the standard input is positioned to\njust after the last matching line before exiting, regardless  of\nthe  presence of trailing context lines.  This enables a calling\nprocess to resume a search.  When grep stops after NUM  matching\nlines,  it  outputs  any trailing context lines.  When the -c or\n--count option is also  used,  grep  does  not  output  a  count\ngreater  than NUM.  When the -v or --invert-match option is also\nused, grep stops after outputting NUM non-matching lines.\n",
                    "flag": "-l",
                    "long": "--files-with-matches"
                },
                {
                    "name": "-o, --only-matching",
                    "content": "Print only the matched (non-empty) parts  of  a  matching  line,\nwith each such part on a separate output line.\n",
                    "flag": "-o",
                    "long": "--only-matching"
                },
                {
                    "name": "-q, --quiet, --silent",
                    "content": "Quiet;   do   not  write  anything  to  standard  output.   Exit\nimmediately with zero status if any match is found, even  if  an\nerror was detected.  Also see the -s or --no-messages option.\n",
                    "flag": "-q",
                    "long": "--silent"
                },
                {
                    "name": "-s, --no-messages",
                    "content": "Suppress error messages about nonexistent or unreadable files.\n\nOutput Line Prefix Control",
                    "flag": "-s",
                    "long": "--no-messages"
                },
                {
                    "name": "-b, --byte-offset",
                    "content": "Print  the 0-based byte offset within the input file before each\nline of output.  If -o (--only-matching) is specified, print the\noffset of the matching part itself.\n",
                    "flag": "-b",
                    "long": "--byte-offset"
                },
                {
                    "name": "-H, --with-filename",
                    "content": "Print  the  file  name for each match.  This is the default when\nthere is more than one file to search.  This is a GNU extension.\n",
                    "flag": "-H",
                    "long": "--with-filename"
                },
                {
                    "name": "-h, --no-filename",
                    "content": "Suppress the prefixing of file names on  output.   This  is  the\ndefault  when there is only one file (or only standard input) to\nsearch.\n\n--label=LABEL\nDisplay input actually  coming  from  standard  input  as  input\ncoming  from  file  LABEL.  This can be useful for commands that\ntransform a file's contents before  searching,  e.g.,  gzip  -cd\nfoo.gz  |  grep  --label=foo -H 'some pattern'.  See also the -H\noption.\n",
                    "flag": "-h",
                    "long": "--no-filename"
                },
                {
                    "name": "-n, --line-number",
                    "content": "Prefix each line of output with the 1-based line  number  within\nits input file.\n",
                    "flag": "-n",
                    "long": "--line-number"
                },
                {
                    "name": "-T, --initial-tab",
                    "content": "Make  sure  that the first character of actual line content lies\non a tab stop, so that the alignment of tabs looks normal.  This\nis  useful  with  options that prefix their output to the actual\ncontent: -H,-n, and -b.  In order  to  improve  the  probability\nthat lines from a single file will all start at the same column,\nthis also causes the line number and byte offset (if present) to\nbe printed in a minimum size field width.\n",
                    "flag": "-T",
                    "long": "--initial-tab"
                },
                {
                    "name": "-Z, --null",
                    "content": "Output  a  zero  byte  (the  ASCII NUL character) instead of the\ncharacter that normally follows a file name.  For example,  grep\n-lZ  outputs  a  zero  byte  after each file name instead of the\nusual newline.  This option makes the output  unambiguous,  even\nin the presence of file names containing unusual characters like\nnewlines.  This option can  be  used  with  commands  like  find\n-print0,  perl  -0,  sort  -z, and xargs -0 to process arbitrary\nfile names, even those that contain newline characters.\n\nContext Line Control\n-A NUM, --after-context=NUM\nPrint NUM  lines  of  trailing  context  after  matching  lines.\nPlaces   a  line  containing  a  group  separator  (--)  between\ncontiguous groups of matches.  With the  -o  or  --only-matching\noption, this has no effect and a warning is given.\n\n-B NUM, --before-context=NUM\nPrint  NUM  lines  of  leading  context  before  matching lines.\nPlaces  a  line  containing  a  group  separator  (--)   between\ncontiguous  groups  of  matches.  With the -o or --only-matching\noption, this has no effect and a warning is given.\n\n-C NUM, -NUM, --context=NUM\nPrint NUM lines of output context.  Places a line  containing  a\ngroup separator (--) between contiguous groups of matches.  With\nthe -o or --only-matching option,  this  has  no  effect  and  a\nwarning is given.\n\n--group-separator=SEP\nWhen  -A,  -B, or -C are in use, print SEP instead of -- between\ngroups of lines.\n",
                    "flag": "-Z",
                    "long": "--null"
                },
                {
                    "name": "--no-group-separator",
                    "content": "When -A, -B, or -C are in use, do not print a separator  between\ngroups of lines.\n\nFile and Directory Selection",
                    "long": "--no-group-separator"
                },
                {
                    "name": "-a, --text",
                    "content": "Process  a binary file as if it were text; this is equivalent to\nthe --binary-files=text option.\n\n--binary-files=TYPE\nIf a file's data or metadata indicate  that  the  file  contains\nbinary  data,  assume  that  the file is of type TYPE.  Non-text\nbytes indicate binary data; these are either output  bytes  that\nare  improperly  encoded  for  the current locale, or null input\nbytes when the -z option is not given.\n\nBy default, TYPE is binary, and  grep  suppresses  output  after\nnull  input  binary  data  is  discovered, and suppresses output\nlines that contain improperly encoded data.  When some output is\nsuppressed,  grep  follows  any  output  with a one-line message\nsaying that a binary file matches.\n\nIf TYPE is without-match, when grep discovers null input  binary\ndata  it  assumes that the rest of the file does not match; this\nis equivalent to the -I option.\n\nIf TYPE is text, grep processes a binary  file  as  if  it  were\ntext; this is equivalent to the -a option.\n\nWhen  type  is  binary,  grep  may  treat non-text bytes as line\nterminators even without the -z  option.   This  means  choosing\nbinary  versus text can affect whether a pattern matches a file.\nFor example, when type is binary the pattern q$  might  match  q\nimmediately  followed  by  a  null byte, even though this is not\nmatched when type is text.  Conversely, when type is binary  the\npattern . (period) might not match a null byte.\n\nWarning:  The  -a  option might output binary garbage, which can\nhave nasty side effects if the output is a terminal and  if  the\nterminal driver interprets some of it as commands.  On the other\nhand, when reading files whose text encodings  are  unknown,  it\ncan   be  helpful  to  use  -a  or  to  set  LCALL='C'  in  the\nenvironment, in order to find more matches even if  the  matches\nare unsafe for direct display.\n\n-D ACTION, --devices=ACTION\nIf  an  input  file  is  a device, FIFO or socket, use ACTION to\nprocess it.  By  default,  ACTION  is  read,  which  means  that\ndevices are read just as if they were ordinary files.  If ACTION\nis skip, devices are silently skipped.\n\n-d ACTION, --directories=ACTION\nIf an input file is a directory, use ACTION to process  it.   By\ndefault,  ACTION is read, i.e., read directories just as if they\nwere  ordinary  files.   If  ACTION  is  skip,   silently   skip\ndirectories.   If  ACTION  is recurse, read all files under each\ndirectory, recursively, following symbolic links  only  if  they\nare on the command line.  This is equivalent to the -r option.\n\n--exclude=GLOB\nSkip  any  command-line file with a name suffix that matches the\npattern GLOB, using wildcard matching; a name suffix  is  either\nthe  whole name, or a trailing part that starts with a non-slash\ncharacter immediately after a  slash  (/)  in  the  name.   When\nsearching  recursively, skip any subfile whose base name matches\nGLOB; the base name is the part after the last slash.  A pattern\ncan  use *, ?, and [...] as wildcards, and \\ to quote a wildcard\nor backslash character literally.\n\n--exclude-from=FILE\nSkip files whose base name matches any of  the  file-name  globs\nread  from  FILE  (using  wildcard  matching  as described under\n--exclude).\n\n--exclude-dir=GLOB\nSkip any command-line directory with a name suffix that  matches\nthe   pattern   GLOB.   When  searching  recursively,  skip  any\nsubdirectory whose base name matches GLOB.  Ignore any redundant\ntrailing slashes in GLOB.\n\n-I     Process  a  binary  file as if it did not contain matching data;\nthis is equivalent to the --binary-files=without-match option.\n\n--include=GLOB\nSearch only files whose base name matches GLOB  (using  wildcard\nmatching   as  described  under  --exclude).   If  contradictory\n--include and --exclude options are given, the last matching one\nwins.   If  no  --include  or --exclude options match, a file is\nincluded unless the first such option is --include.\n",
                    "flag": "-a",
                    "long": "--text"
                },
                {
                    "name": "-r, --recursive",
                    "content": "Read all files  under  each  directory,  recursively,  following\nsymbolic  links only if they are on the command line.  Note that\nif no file  operand  is  given,  B<grep>  searches  the  working\ndirectory.  This is equivalent to the -d recurse option.\n",
                    "flag": "-r",
                    "long": "--recursive"
                },
                {
                    "name": "-R, --dereference-recursive",
                    "content": "Read  all  files  under each directory, recursively.  Follow all\nsymbolic links, unlike -r.\n\nOther Options",
                    "flag": "-R",
                    "long": "--dereference-recursive"
                },
                {
                    "name": "--line-buffered",
                    "content": "Use line buffering on output.   This  can  cause  a  performance\npenalty.\n",
                    "long": "--line-buffered"
                },
                {
                    "name": "-U, --binary",
                    "content": "Treat  the  file(s) as binary.  By default, under MS-DOS and MS-\nWindows, grep guesses whether  a  file  is  text  or  binary  as\ndescribed  for  the  --binary-files option.  If grep decides the\nfile is a text file,  it  strips  the  CR  characters  from  the\noriginal file contents (to make regular expressions with ^ and $\nwork  correctly).   Specifying  -U  overrules  this   guesswork,\ncausing  all  files  to  be  read  and  passed  to  the matching\nmechanism verbatim; if the file is a text file with CR/LF  pairs\nat   the  end  of  each  line,  this  will  cause  some  regular\nexpressions to fail.  This option has  no  effect  on  platforms\nother than MS-DOS and MS-Windows.\n",
                    "flag": "-U",
                    "long": "--binary"
                },
                {
                    "name": "-z, --null-data",
                    "content": "Treat  input  and  output  data  as  sequences  of  lines,  each\nterminated by a zero byte (the ASCII NUL character) instead of a\nnewline.   Like the -Z or --null option, this option can be used\nwith commands like sort -z to process arbitrary file names.\n",
                    "flag": "-z",
                    "long": "--null-data"
                }
            ]
        },
        "REGULAR EXPRESSIONS": {
            "content": "A regular expression is a pattern that  describes  a  set  of  strings.\nRegular   expressions   are   constructed   analogously  to  arithmetic\nexpressions, by using various operators to combine smaller expressions.\n\ngrep understands three different versions of regular expression syntax:\n\"basic\"  (BRE),  \"extended\" (ERE) and \"perl\" (PCRE).  In GNU grep there\nis no difference in available functionality between basic and  extended\nsyntaxes.  In other implementations, basic regular expressions are less\npowerful.   The  following  description  applies  to  extended  regular\nexpressions;  differences  for basic regular expressions are summarized\nafterwards.   Perl-compatible  regular  expressions   give   additional\nfunctionality,    and    are   documented   in   B<pcresyntax>(3)   and\nB<pcrepattern>(3), but work only if PCRE support is enabled.\n\nThe fundamental building blocks are the regular expressions that  match\na single character.  Most characters, including all letters and digits,\nare regular expressions that match themselves.  Any meta-character with\nspecial meaning may be quoted by preceding it with a backslash.\n\nThe  period  . matches any single character.  It is unspecified whether\nit matches an encoding error.\n\nCharacter Classes and Bracket Expressions\nA bracket expression is a list of characters enclosed by [ and  ].   It\nmatches  any  single character in that list.  If the first character of\nthe list is the caret ^ then it matches any character not in the  list;\nit  is  unspecified whether it matches an encoding error.  For example,\nthe regular expression [0123456789] matches any single digit.\n\nWithin a  bracket  expression,  a  range  expression  consists  of  two\ncharacters separated by a hyphen.  It matches any single character that\nsorts  between  the  two  characters,  inclusive,  using  the  locale's\ncollating  sequence  and  character set.  For example, in the default C\nlocale, [a-d] is equivalent to [abcd].  Many locales sort characters in\ndictionary   order,  and  in  these  locales  [a-d]  is  typically  not\nequivalent to [abcd]; it might be equivalent to [aBbCcDd], for example.\nTo  obtain  the  traditional interpretation of bracket expressions, you\ncan use the C locale by setting the LCALL environment variable to  the\nvalue C.\n\nFinally,  certain  named  classes  of  characters are predefined within\nbracket expressions, as follows.  Their names are self explanatory, and\nthey   are   [:alnum:],  [:alpha:],  [:blank:],  [:cntrl:],  [:digit:],\n[:graph:], [:lower:], [:print:], [:punct:], [:space:],  [:upper:],  and\n[:xdigit:].   For  example,  [[:alnum:]]  means  the character class of\nnumbers and letters in the current locale.  In the C locale  and  ASCII\ncharacter  set  encoding,  this is the same as [0-9A-Za-z].  (Note that\nthe brackets in these class names are part of the symbolic  names,  and\nmust  be  included  in  addition to the brackets delimiting the bracket\nexpression.)  Most meta-characters lose their  special  meaning  inside\nbracket  expressions.   To  include  a  literal ] place it first in the\nlist.  Similarly, to include a literal ^ place it anywhere  but  first.\nFinally, to include a literal - place it last.\n\nAnchoring\nThe caret ^ and the dollar sign $ are meta-characters that respectively\nmatch the empty string at the beginning and end of a line.\n\nThe Backslash Character and Special Expressions\nThe symbols \\< and \\>  respectively  match  the  empty  string  at  the\nbeginning and end of a word.  The symbol \\b matches the empty string at\nthe edge of a word, and \\B matches the empty string provided  it's  not\nat the edge of a word.  The symbol \\w is a synonym for [[:alnum:]] and\n\\W is a synonym for [^[:alnum:]].\n\nRepetition\nA regular expression may be  followed  by  one  of  several  repetition\noperators:\n?      The preceding item is optional and matched at most once.\n*      The preceding item will be matched zero or more times.\n+      The preceding item will be matched one or more times.\n{n}    The preceding item is matched exactly n times.\n{n,}   The preceding item is matched n or more times.\n{,m}   The  preceding  item  is matched at most m times.  This is a GNU\nextension.\n{n,m}  The preceding item is matched at least n  times,  but  not  more\nthan m times.\n\nConcatenation\nTwo  regular  expressions  may  be  concatenated; the resulting regular\nexpression matches any string formed by  concatenating  two  substrings\nthat respectively match the concatenated expressions.\n\nAlternation\nTwo  regular  expressions  may  be  joined by the infix operator |; the\nresulting  regular  expression  matches  any  string  matching   either\nalternate expression.\n\nPrecedence\nRepetition  takes  precedence  over  concatenation, which in turn takes\nprecedence over alternation.  A whole expression  may  be  enclosed  in\nparentheses   to   override   these   precedence   rules   and  form  a\nsubexpression.\n\nBack-references and Subexpressions\nThe back-reference \\n, where n is a single digit, matches the substring\npreviously  matched  by  the  nth  parenthesized  subexpression  of the\nregular expression.\n\nBasic vs Extended Regular Expressions\nIn basic regular expressions the meta-characters ?, +, {, |, (,  and  )\nlose  their  special  meaning; instead use the backslashed versions \\?,\n\\+, \\{, \\|, \\(, and \\).\n",
            "subsections": []
        },
        "EXIT STATUS": {
            "content": "Normally the exit status is 0 if a line is selected, 1 if no lines were\nselected, and 2 if an error occurred.  However, if the -q or --quiet or\n--silent is used and a line is selected, the exit status is 0  even  if\nan error occurred.\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "The   behavior  of  grep  is  affected  by  the  following  environment\nvariables.\n\nThe locale for category LCfoo is  specified  by  examining  the  three\nenvironment  variables  LCALL, LCfoo, LANG, in that order.  The first\nof these variables that is set specifies the locale.  For  example,  if\nLCALL  is not set, but LCMESSAGES is set to ptBR, then the Brazilian\nPortuguese locale is used for the LCMESSAGES category.  The  C  locale\nis  used  if none of these environment variables are set, if the locale\ncatalog is not installed, or if grep was  not  compiled  with  national\nlanguage support (NLS).  The shell command locale -a lists locales that\nare currently available.\n\nGREPCOLOR\nThis variable specifies the  color  used  to  highlight  matched\n(non-empty) text.  It is deprecated in favor of GREPCOLORS, but\nstill supported.  The mt, ms, and mc capabilities of GREPCOLORS\nhave  priority  over  it.  It can only specify the color used to\nhighlight the matching non-empty text in any  matching  line  (a\nselected  line  when the -v command-line option is omitted, or a\ncontext line when -v is specified).  The default is 01;31, which\nmeans  a  bold  red  foreground  text  on the terminal's default\nbackground.\n\nGREPCOLORS\nSpecifies the colors and  other  attributes  used  to  highlight\nvarious  parts  of  the  output.  Its value is a colon-separated\nlist      of      capabilities      that       defaults       to\nms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36  with  the  rv\nand ne boolean capabilities omitted  (i.e.,  false).   Supported\ncapabilities are as follows.\n\nsl=    SGR  substring  for  whole selected lines (i.e., matching\nlines when the -v command-line option is omitted, or non-\nmatching  lines  when  -v  is specified).  If however the\nboolean rv capability and the -v command-line option  are\nboth  specified,  it  applies  to  context matching lines\ninstead.  The default  is  empty  (i.e.,  the  terminal's\ndefault color pair).\n\ncx=    SGR substring for whole context lines (i.e., non-matching\nlines when the -v  command-line  option  is  omitted,  or\nmatching  lines  when  -v  is specified).  If however the\nboolean rv capability and the -v command-line option  are\nboth specified, it applies to selected non-matching lines\ninstead.  The default  is  empty  (i.e.,  the  terminal's\ndefault color pair).\n\nrv     Boolean  value  that reverses (swaps) the meanings of the\nsl= and cx= capabilities when the -v command-line  option\nis specified.  The default is false (i.e., the capability\nis omitted).\n\nmt=01;31\nSGR substring for matching non-empty text in any matching\nline  (i.e.,  a  selected  line  when the -v command-line\noption  is  omitted,  or  a  context  line  when  -v   is\nspecified).   Setting  this is equivalent to setting both\nms= and mc= at once to the same value.  The default is  a\nbold   red   text   foreground   over  the  current  line\nbackground.\n\nms=01;31\nSGR substring for matching non-empty text in  a  selected\nline.  (This is only used when the -v command-line option\nis omitted.)  The effect  of  the  sl=  (or  cx=  if  rv)\ncapability  remains  active  when  this  kicks  in.   The\ndefault is a bold red text foreground  over  the  current\nline background.\n\nmc=01;31\nSGR  substring  for  matching non-empty text in a context\nline.  (This is only used when the -v command-line option\nis  specified.)   The  effect  of  the cx= (or sl= if rv)\ncapability  remains  active  when  this  kicks  in.   The\ndefault  is  a  bold red text foreground over the current\nline background.\n\nfn=35  SGR substring for file names prefixing any content  line.\nThe  default  is  a  magenta  text  foreground  over  the\nterminal's default background.\n\nln=32  SGR substring for  line  numbers  prefixing  any  content\nline.   The  default  is a green text foreground over the\nterminal's default background.\n\nbn=32  SGR substring for  byte  offsets  prefixing  any  content\nline.   The  default  is a green text foreground over the\nterminal's default background.\n\nse=36  SGR substring for separators that  are  inserted  between\nselected  line  fields  (:), between context line fields,\n(-), and between groups of adjacent  lines  when  nonzero\ncontext  is  specified  (--).  The default is a cyan text\nforeground over the terminal's default background.\n\nne     Boolean value that prevents clearing to the end  of  line\nusing  Erase  in  Line  (EL) to Right (\\33[K) each time a\ncolorized item ends.  This  is  needed  on  terminals  on\nwhich  EL  is  not  supported.  It is otherwise useful on\nterminals for which the  backcolorerase  (bce)  boolean\nterminfo  capability  does  not  apply,  when  the chosen\nhighlight colors do not affect the background, or when EL\nis  too  slow or causes too much flicker.  The default is\nfalse (i.e., the capability is omitted).\n\nNote that boolean capabilities have  no  =...  part.   They  are\nomitted (i.e., false) by default and become true when specified.\n\nSee   the   Select   Graphic  Rendition  (SGR)  section  in  the\ndocumentation of the text terminal that is  used  for  permitted\nvalues   and  their  meaning  as  character  attributes.   These\nsubstring values are integers in decimal representation and  can\nbe  concatenated with semicolons.  grep takes care of assembling\nthe result into a  complete  SGR  sequence  (\\33[...m).   Common\nvalues to concatenate include 1 for bold, 4 for underline, 5 for\nblink, 7 for inverse, 39 for default foreground color, 30 to  37\nfor  foreground  colors,  90  to 97 for 16-color mode foreground\ncolors, 38;5;0 to 38;5;255  for  88-color  and  256-color  modes\nforeground colors, 49 for default background color, 40 to 47 for\nbackground colors, 100  to  107  for  16-color  mode  background\ncolors,  and 48;5;0 to 48;5;255 for 88-color and 256-color modes\nbackground colors.\n\nLCALL, LCCOLLATE, LANG\nThese variables specify the locale for the LCCOLLATE  category,\nwhich  determines the collating sequence used to interpret range\nexpressions like [a-z].\n\nLCALL, LCCTYPE, LANG\nThese variables specify the locale for  the  LCCTYPE  category,\nwhich  determines the type of characters, e.g., which characters\nare whitespace.  This category  also  determines  the  character\nencoding,  that  is, whether text is encoded in UTF-8, ASCII, or\nsome other encoding.  In the C or POSIX locale,  all  characters\nare  encoded  as  a  single  byte  and  every  byte  is  a valid\ncharacter.\n\nLCALL, LCMESSAGES, LANG\nThese variables specify the locale for the LCMESSAGES category,\nwhich  determines the language that grep uses for messages.  The\ndefault C locale uses American English messages.\n\nPOSIXLYCORRECT\nIf set, grep behaves as POSIX requires; otherwise, grep  behaves\nmore  like other GNU programs.  POSIX requires that options that\nfollow file names must be treated as  file  names;  by  default,\nsuch  options  are permuted to the front of the operand list and\nare treated as options.  Also, POSIX requires that  unrecognized\noptions be diagnosed as \"illegal\", but since they are not really\nagainst the law the default is to diagnose  them  as  \"invalid\".\nPOSIXLYCORRECT   also   disables  NGNUnonoptionargvflags,\ndescribed below.\n\nNGNUnonoptionargvflags\n(Here N is grep's numeric process ID.)  If the ith character  of\nthis  environment variable's value is 1, do not consider the ith\noperand of grep to be an option, even if it appears to  be  one.\nA  shell  can  put  this  variable  in  the environment for each\ncommand it runs, specifying which operands are  the  results  of\nfile name wildcard expansion and therefore should not be treated\nas options.  This behavior is available  only  with  the  GNU  C\nlibrary, and only when POSIXLYCORRECT is not set.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "This  man  page  is maintained only fitfully; the full documentation is\noften more up-to-date.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1998-2000, 2002, 2005-2021 Free Software Foundation, Inc.\n\nThis is free software; see the source for copying conditions.  There is\nNO  warranty;  not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Reporting Bugs\nEmail bug reports to the bug-reporting address <bug-grep@gnu.org>.   An\nemail  archive  <https://lists.gnu.org/mailman/listinfo/bug-grep> and a\nbug  tracker   <https://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep>\nare available.\n\nKnown Bugs\nLarge  repetition  counts  in the {n,m} construct may cause grep to use\nlots of memory.  In addition, certain other obscure regular expressions\nrequire  exponential  time  and space, and may cause grep to run out of\nmemory.\n\nBack-references are very slow, and may require exponential time.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "The following example outputs the location and  contents  of  any  line\ncontaining  \"f\" and ending in \".c\", within all files in the current di-\nrectory whose names contain \"g\" and end in \".h\".  The -n option outputs\nline  numbers,  the  --  argument treats expansions of \"*g*.h\" starting\nwith \"-\" as file names not options, and the empty file /dev/null causes\nfile names to be output even if only one file name happens to be of the\nform \"*g*.h\".\n\n$ grep -n -- 'f.*\\.c$' *g*.h /dev/null\nargmatch.h:1:/* definitions and prototypes for argmatch.c\n\nThe only line that matches is line 1 of argmatch.h.  Note that the reg-\nular  expression  syntax  used in the pattern differs from the globbing\nsyntax that the shell uses to match file names.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Regular Manual Pages\nawk(1), cmp(1), diff(1), find(1), perl(1), sed(1),  sort(1),  xargs(1),\nread(2),  pcre(3), pcresyntax(3), pcrepattern(3), terminfo(5), glob(7),\nregex(7)\n\nFull Documentation\nA complete manual <https://www.gnu.org/software/grep/manual/> is avail-\nable.   If  the  info  and grep programs are properly installed at your\nsite, the command\n\ninfo grep\n\nshould give you access to the complete manual.\n\nGNU grep 3.7                      2019-12-29                           GREP(1)",
            "subsections": []
        }
    },
    "summary": "grep, egrep, fgrep, rgrep - print lines that match patterns",
    "flags": [
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Output the version number of grep and exit. Pattern Syntax"
        },
        {
            "flag": "-E",
            "long": "--extended-regexp",
            "arg": null,
            "description": "Interpret PATTERNS as extended regular expressions (EREs, see below)."
        },
        {
            "flag": "-F",
            "long": "--fixed-strings",
            "arg": null,
            "description": "Interpret PATTERNS as fixed strings, not regular expressions."
        },
        {
            "flag": "-G",
            "long": "--basic-regexp",
            "arg": null,
            "description": "Interpret PATTERNS as basic regular expressions (BREs, see below). This is the default."
        },
        {
            "flag": "-P",
            "long": "--perl-regexp",
            "arg": null,
            "description": "Interpret I<PATTERNS> as Perl-compatible regular expressions (PCREs). This option is experimental when combined with the -z (--null-data) option, and grep -P may warn of unimplemented features. Matching Control -e PATTERNS, --regexp=PATTERNS Use PATTERNS as the patterns. If this option is used multiple times or is combined with the -f (--file) option, search for all patterns given. This option can be used to protect a pattern beginning with \"-\". -f FILE, --file=FILE Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing."
        },
        {
            "flag": "-i",
            "long": "--ignore-case",
            "arg": null,
            "description": "Ignore case distinctions in patterns and input data, so that characters that differ only in case match each other."
        },
        {
            "flag": "",
            "long": "--no-ignore-case",
            "arg": null,
            "description": "Do not ignore case distinctions in patterns and input data. This is the default. This option is useful for passing to shell scripts that already use -i, to cancel its effects because the two options override each other."
        },
        {
            "flag": "-v",
            "long": "--invert-match",
            "arg": null,
            "description": "Invert the sense of matching, to select non-matching lines."
        },
        {
            "flag": "-w",
            "long": "--word-regexp",
            "arg": null,
            "description": "Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. This option has no effect if -x is also specified."
        },
        {
            "flag": "-x",
            "long": "--line-regexp",
            "arg": null,
            "description": "Select only those matches that exactly match the whole line. For a regular expression pattern, this is like parenthesizing the pattern and then surrounding it with ^ and $. -y Obsolete synonym for -i. General Output Control"
        },
        {
            "flag": "-c",
            "long": "--count",
            "arg": null,
            "description": "Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines."
        },
        {
            "flag": "",
            "long": null,
            "arg": null,
            "description": "Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal. The colors are defined by the environment variable GREPCOLORS. The deprecated environment variable GREPCOLOR is still supported, but its setting does not have priority. WHEN is never, always, or auto."
        },
        {
            "flag": "-L",
            "long": "--files-without-match",
            "arg": null,
            "description": "Suppress normal output; instead print the name of each input file from which no output would normally have been printed."
        },
        {
            "flag": "-l",
            "long": "--files-with-matches",
            "arg": null,
            "description": "Suppress normal output; instead print the name of each input file from which output would normally have been printed. Scanning each input file stops upon first match. -m NUM, --max-count=NUM Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM. When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines."
        },
        {
            "flag": "-o",
            "long": "--only-matching",
            "arg": null,
            "description": "Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line."
        },
        {
            "flag": "-q",
            "long": "--silent",
            "arg": null,
            "description": "Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages option."
        },
        {
            "flag": "-s",
            "long": "--no-messages",
            "arg": null,
            "description": "Suppress error messages about nonexistent or unreadable files. Output Line Prefix Control"
        },
        {
            "flag": "-b",
            "long": "--byte-offset",
            "arg": null,
            "description": "Print the 0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print the offset of the matching part itself."
        },
        {
            "flag": "-H",
            "long": "--with-filename",
            "arg": null,
            "description": "Print the file name for each match. This is the default when there is more than one file to search. This is a GNU extension."
        },
        {
            "flag": "-h",
            "long": "--no-filename",
            "arg": null,
            "description": "Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. --label=LABEL Display input actually coming from standard input as input coming from file LABEL. This can be useful for commands that transform a file's contents before searching, e.g., gzip -cd foo.gz | grep --label=foo -H 'some pattern'. See also the -H option."
        },
        {
            "flag": "-n",
            "long": "--line-number",
            "arg": null,
            "description": "Prefix each line of output with the 1-based line number within its input file."
        },
        {
            "flag": "-T",
            "long": "--initial-tab",
            "arg": null,
            "description": "Make sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal. This is useful with options that prefix their output to the actual content: -H,-n, and -b. In order to improve the probability that lines from a single file will all start at the same column, this also causes the line number and byte offset (if present) to be printed in a minimum size field width."
        },
        {
            "flag": "-Z",
            "long": "--null",
            "arg": null,
            "description": "Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, grep -lZ outputs a zero byte after each file name instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary file names, even those that contain newline characters. Context Line Control -A NUM, --after-context=NUM Print NUM lines of trailing context after matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. -B NUM, --before-context=NUM Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. -C NUM, -NUM, --context=NUM Print NUM lines of output context. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. --group-separator=SEP When -A, -B, or -C are in use, print SEP instead of -- between groups of lines."
        },
        {
            "flag": "",
            "long": "--no-group-separator",
            "arg": null,
            "description": "When -A, -B, or -C are in use, do not print a separator between groups of lines. File and Directory Selection"
        },
        {
            "flag": "-a",
            "long": "--text",
            "arg": null,
            "description": "Process a binary file as if it were text; this is equivalent to the --binary-files=text option. --binary-files=TYPE If a file's data or metadata indicate that the file contains binary data, assume that the file is of type TYPE. Non-text bytes indicate binary data; these are either output bytes that are improperly encoded for the current locale, or null input bytes when the -z option is not given. By default, TYPE is binary, and grep suppresses output after null input binary data is discovered, and suppresses output lines that contain improperly encoded data. When some output is suppressed, grep follows any output with a one-line message saying that a binary file matches. If TYPE is without-match, when grep discovers null input binary data it assumes that the rest of the file does not match; this is equivalent to the -I option. If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option. When type is binary, grep may treat non-text bytes as line terminators even without the -z option. This means choosing binary versus text can affect whether a pattern matches a file. For example, when type is binary the pattern q$ might match q immediately followed by a null byte, even though this is not matched when type is text. Conversely, when type is binary the pattern . (period) might not match a null byte. Warning: The -a option might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands. On the other hand, when reading files whose text encodings are unknown, it can be helpful to use -a or to set LCALL='C' in the environment, in order to find more matches even if the matches are unsafe for direct display. -D ACTION, --devices=ACTION If an input file is a device, FIFO or socket, use ACTION to process it. By default, ACTION is read, which means that devices are read just as if they were ordinary files. If ACTION is skip, devices are silently skipped. -d ACTION, --directories=ACTION If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ordinary files. If ACTION is skip, silently skip directories. If ACTION is recurse, read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -r option. --exclude=GLOB Skip any command-line file with a name suffix that matches the pattern GLOB, using wildcard matching; a name suffix is either the whole name, or a trailing part that starts with a non-slash character immediately after a slash (/) in the name. When searching recursively, skip any subfile whose base name matches GLOB; the base name is the part after the last slash. A pattern can use *, ?, and [...] as wildcards, and \\ to quote a wildcard or backslash character literally. --exclude-from=FILE Skip files whose base name matches any of the file-name globs read from FILE (using wildcard matching as described under --exclude). --exclude-dir=GLOB Skip any command-line directory with a name suffix that matches the pattern GLOB. When searching recursively, skip any subdirectory whose base name matches GLOB. Ignore any redundant trailing slashes in GLOB. -I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option. --include=GLOB Search only files whose base name matches GLOB (using wildcard matching as described under --exclude). If contradictory --include and --exclude options are given, the last matching one wins. If no --include or --exclude options match, a file is included unless the first such option is --include."
        },
        {
            "flag": "-r",
            "long": "--recursive",
            "arg": null,
            "description": "Read all files under each directory, recursively, following symbolic links only if they are on the command line. Note that if no file operand is given, B<grep> searches the working directory. This is equivalent to the -d recurse option."
        },
        {
            "flag": "-R",
            "long": "--dereference-recursive",
            "arg": null,
            "description": "Read all files under each directory, recursively. Follow all symbolic links, unlike -r. Other Options"
        },
        {
            "flag": "",
            "long": "--line-buffered",
            "arg": null,
            "description": "Use line buffering on output. This can cause a performance penalty."
        },
        {
            "flag": "-U",
            "long": "--binary",
            "arg": null,
            "description": "Treat the file(s) as binary. By default, under MS-DOS and MS- Windows, grep guesses whether a file is text or binary as described for the --binary-files option. If grep decides the file is a text file, it strips the CR characters from the original file contents (to make regular expressions with ^ and $ work correctly). Specifying -U overrules this guesswork, causing all files to be read and passed to the matching mechanism verbatim; if the file is a text file with CR/LF pairs at the end of each line, this will cause some regular expressions to fail. This option has no effect on platforms other than MS-DOS and MS-Windows."
        },
        {
            "flag": "-z",
            "long": "--null-data",
            "arg": null,
            "description": "Treat input and output data as sequences of lines, each terminated by a zero byte (the ASCII NUL character) instead of a newline. Like the -Z or --null option, this option can be used with commands like sort -z to process arbitrary file names."
        }
    ],
    "examples": [
        "The following example outputs the location and  contents  of  any  line",
        "containing  \"f\" and ending in \".c\", within all files in the current di-",
        "rectory whose names contain \"g\" and end in \".h\".  The -n option outputs",
        "line  numbers,  the  --  argument treats expansions of \"*g*.h\" starting",
        "with \"-\" as file names not options, and the empty file /dev/null causes",
        "file names to be output even if only one file name happens to be of the",
        "form \"*g*.h\".",
        "$ grep -n -- 'f.*\\.c$' *g*.h /dev/null",
        "argmatch.h:1:/* definitions and prototypes for argmatch.c",
        "The only line that matches is line 1 of argmatch.h.  Note that the reg-",
        "ular  expression  syntax  used in the pattern differs from the globbing",
        "syntax that the shell uses to match file names."
    ],
    "see_also": [
        {
            "name": "awk",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/awk/1/json"
        },
        {
            "name": "cmp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cmp/1/json"
        },
        {
            "name": "diff",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/diff/1/json"
        },
        {
            "name": "find",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/find/1/json"
        },
        {
            "name": "perl",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/perl/1/json"
        },
        {
            "name": "sed",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/sed/1/json"
        },
        {
            "name": "sort",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/sort/1/json"
        },
        {
            "name": "xargs",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/xargs/1/json"
        },
        {
            "name": "read",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/read/2/json"
        },
        {
            "name": "pcre",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/pcre/3/json"
        },
        {
            "name": "pcresyntax",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/pcresyntax/3/json"
        },
        {
            "name": "pcrepattern",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/pcrepattern/3/json"
        },
        {
            "name": "terminfo",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/terminfo/5/json"
        },
        {
            "name": "glob",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/glob/7/json"
        },
        {
            "name": "regex",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/regex/7/json"
        }
    ]
}