1GREP(1)                     General Commands Manual                    GREP(1)
2
3
4

NAME

6       grep, egrep, fgrep - print lines matching a pattern
7

SYNOPSIS

9       grep [OPTIONS] PATTERN [FILE...]
10       grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
11

DESCRIPTION

13       grep  searches the named input FILEs (or standard input if no files are
14       named, or if a single hyphen-minus (-) is given as file name) for lines
15       containing  a  match to the given PATTERN.  By default, grep prints the
16       matching lines.
17
18       In addition, two variant programs egrep and fgrep are available.  egrep
19       is  the  same  as  grep -E.   fgrep  is  the  same  as grep -F.  Direct
20       invocation as either egrep or fgrep is deprecated, but is  provided  to
21       allow historical applications that rely on them to run unmodified.
22

OPTIONS

24   Generic Program Information
25       --help Print  a  usage  message  briefly summarizing these command-line
26              options and the bug-reporting address, then exit.
27
28       -V, --version
29              Print the version number of grep to the standard output  stream.
30              This  version  number should be included in all bug reports (see
31              below).
32
33   Matcher Selection
34       -E, --extended-regexp
35              Interpret PATTERN as an extended regular  expression  (ERE,  see
36              below).  (-E is specified by POSIX.)
37
38       -F, --fixed-strings, --fixed-regexp
39              Interpret  PATTERN  as  a  list  of  fixed strings, separated by
40              newlines, any of which is to be matched.  (-F  is  specified  by
41              POSIX,  --fixed-regexp  is an obsoleted alias, please do not use
42              it in new scripts.)
43
44       -G, --basic-regexp
45              Interpret PATTERN  as  a  basic  regular  expression  (BRE,  see
46              below).  This is the default.
47
48       -P, --perl-regexp
49              Interpret  PATTERN as a Perl regular expression.  This is highly
50              experimental and grep -P may warn of unimplemented features.
51
52   Matching Control
53       -e PATTERN, --regexp=PATTERN
54              Use PATTERN as  the  pattern.   This  can  be  used  to  specify
55              multiple search patterns, or to protect a pattern beginning with
56              a hyphen (-).  (-e is specified by POSIX.)
57
58       -f FILE, --file=FILE
59              Obtain patterns  from  FILE,  one  per  line.   The  empty  file
60              contains  zero  patterns, and therefore matches nothing.  (-f is
61              specified by POSIX.)
62
63       -i, --ignore-case
64              Ignore case distinctions in  both  the  PATTERN  and  the  input
65              files.  (-i is specified by POSIX.)
66
67       -v, --invert-match
68              Invert the sense of matching, to select non-matching lines.  (-v
69              is specified by POSIX.)
70
71       -w, --word-regexp
72              Select only those  lines  containing  matches  that  form  whole
73              words.   The  test is that the matching substring must either be
74              at the  beginning  of  the  line,  or  preceded  by  a  non-word
75              constituent  character.  Similarly, it must be either at the end
76              of the line or followed by  a  non-word  constituent  character.
77              Word-constituent   characters   are  letters,  digits,  and  the
78              underscore.
79
80       -x, --line-regexp
81              Select only those matches that exactly  match  the  whole  line.
82              (-x is specified by POSIX.)
83
84       -y     Obsolete synonym for -i.
85
86   General Output Control
87       -c, --count
88              Suppress  normal output; instead print a count of matching lines
89              for each input file.  With the -v,  --invert-match  option  (see
90              below), count non-matching lines.  (-c is specified by POSIX.)
91
92       --color[=WHEN], --colour[=WHEN]
93              Surround   the  matched  (non-empty)  strings,  matching  lines,
94              context lines, file  names,  line  numbers,  byte  offsets,  and
95              separators  (for fields and groups of context lines) with escape
96              sequences to display them in color on the terminal.  The  colors
97              are  defined  by  the  environment  variable  GREP_COLORS.   The
98              deprecated environment variable GREP_COLOR is  still  supported,
99              but  its setting does not have priority.  WHEN is never, always,
100              or auto.
101
102       -L, --files-without-match
103              Suppress normal output; instead print the  name  of  each  input
104              file from which no output would normally have been printed.  The
105              scanning will stop on the first match.
106
107       -l, --files-with-matches
108              Suppress normal output; instead print the  name  of  each  input
109              file  from  which  output would normally have been printed.  The
110              scanning will stop on the first  match.   (-l  is  specified  by
111              POSIX.)
112
113       -m NUM, --max-count=NUM
114              Stop  reading  a file after NUM matching lines.  If the input is
115              standard input from a regular file, and NUM matching  lines  are
116              output,  grep  ensures  that the standard input is positioned to
117              just after the last matching line before exiting, regardless  of
118              the  presence of trailing context lines.  This enables a calling
119              process to resume a search.  When grep stops after NUM  matching
120              lines,  it  outputs  any trailing context lines.  When the -c or
121              --count option is also  used,  grep  does  not  output  a  count
122              greater  than NUM.  When the -v or --invert-match option is also
123              used, grep stops after outputting NUM non-matching lines.
124
125       -o, --only-matching
126              Print only the matched (non-empty) parts  of  a  matching  line,
127              with each such part on a separate output line.
128
129       -q, --quiet, --silent
130              Quiet;   do   not  write  anything  to  standard  output.   Exit
131              immediately with zero status if any match is found, even  if  an
132              error  was  detected.   Also see the -s or --no-messages option.
133              (-q is specified by POSIX.)
134
135       -s, --no-messages
136              Suppress error messages about nonexistent or  unreadable  files.
137              Portability note: unlike GNU grep, 7th Edition Unix grep did not
138              conform to POSIX, because it lacked -q and its -s option behaved
139              like  GNU  grep's  -q option.  USG-style grep also lacked -q but
140              its -s option behaved like GNU  grep.   Portable  shell  scripts
141              should  avoid  both  -q  and -s and should redirect standard and
142              error output to /dev/null instead.  (-s is specified by POSIX.)
143
144   Output Line Prefix Control
145       -b, --byte-offset
146              Print the 0-based byte offset within the input file before  each
147              line of output.  If -o (--only-matching) is specified, print the
148              offset of the matching part itself.
149
150       -H, --with-filename
151              Print the file name for each match.  This is  the  default  when
152              there is more than one file to search.
153
154       -h, --no-filename
155              Suppress  the  prefixing  of  file names on output.  This is the
156              default when there is only one file (or only standard input)  to
157              search.
158
159       --label=LABEL
160              Display  input  actually  coming  from  standard  input as input
161              coming  from  file  LABEL.   This  is  especially  useful   when
162              implementing  tools  like  zgrep,  e.g.,  gzip -cd foo.gz | grep
163              --label=foo -H something.  See also the -H option.
164
165       -n, --line-number
166              Prefix each line of output with the 1-based line  number  within
167              its input file.  (-n is specified by POSIX.)
168
169       -T, --initial-tab
170              Make  sure  that the first character of actual line content lies
171              on a tab stop, so that the alignment of tabs looks normal.  This
172              is  useful  with  options that prefix their output to the actual
173              content: -H,-n, and -b.  In order  to  improve  the  probability
174              that lines from a single file will all start at the same column,
175              this also causes the line number and byte offset (if present) to
176              be printed in a minimum size field width.
177
178       -u, --unix-byte-offsets
179              Report  Unix-style  byte  offsets.   This  switch causes grep to
180              report byte offsets as if the file were a Unix-style text  file,
181              i.e.,  with  CR  characters  stripped  off.   This  will produce
182              results identical to running  grep  on  a  Unix  machine.   This
183              option  has  no  effect unless -b option is also used; it has no
184              effect on platforms other than MS-DOS and MS-Windows.
185
186       -Z, --null
187              Output a zero byte (the ASCII  NUL  character)  instead  of  the
188              character  that normally follows a file name.  For example, grep
189              -lZ outputs a zero byte after each  file  name  instead  of  the
190              usual  newline.   This option makes the output unambiguous, even
191              in the presence of file names containing unusual characters like
192              newlines.   This  option  can  be  used  with commands like find
193              -print0, perl -0, sort -z, and xargs  -0  to  process  arbitrary
194              file names, even those that contain newline characters.
195
196   Context Line Control
197       -A NUM, --after-context=NUM
198              Print  NUM  lines  of  trailing  context  after  matching lines.
199              Places a line containing  a  group  separator  (described  under
200              --group-separator)  between  contiguous groups of matches.  With
201              the -o or --only-matching option,  this  has  no  effect  and  a
202              warning is given.
203
204       -B NUM, --before-context=NUM
205              Print  NUM  lines  of  leading  context  before  matching lines.
206              Places a line containing  a  group  separator  (described  under
207              --group-separator)  between  contiguous groups of matches.  With
208              the -o or --only-matching option,  this  has  no  effect  and  a
209              warning is given.
210
211       -C NUM, -NUM, --context=NUM
212              Print  NUM  lines of output context.  Places a line containing a
213              group  separator  (described  under  --group-separator)  between
214              contiguous  groups  of  matches.  With the -o or --only-matching
215              option, this has no effect and a warning is given.
216
217       --group-separator=SEP
218              Use SEP as a group separator. By default SEP  is  double  hyphen
219              (--).
220
221       --no-group-separator
222              Use empty string as a group separator.
223
224   File and Directory Selection
225       -a, --text
226              Process  a binary file as if it were text; this is equivalent to
227              the --binary-files=text option.
228
229       --binary-files=TYPE
230              If the first few bytes of a file indicate that the file contains
231              binary  data, assume that the file is of type TYPE.  By default,
232              TYPE is binary, and grep  normally  outputs  either  a  one-line
233              message  saying  that  a  binary  file matches, or no message if
234              there is no match.  If TYPE is without-match, grep assumes  that
235              a  binary  file  does  not  match;  this is equivalent to the -I
236              option.  If TYPE is text, grep processes a binary file as if  it
237              were  text;  this is equivalent to the -a option.  Warning: grep
238              --binary-files=text might output binary garbage, which can  have
239              nasty  side  effects  if  the  output  is  a terminal and if the
240              terminal driver interprets some of it as commands.
241
242       -D ACTION, --devices=ACTION
243              If an input file is a device, FIFO  or  socket,  use  ACTION  to
244              process  it.   By  default,  ACTION  is  read,  which means that
245              devices are read just as if they were ordinary files.  If ACTION
246              is skip, devices are silently skipped.
247
248       -d ACTION, --directories=ACTION
249              If  an  input file is a directory, use ACTION to process it.  By
250              default, ACTION is read, i.e., read directories just as if  they
251              were   ordinary   files.   If  ACTION  is  skip,  silently  skip
252              directories.  If ACTION is recurse, read all  files  under  each
253              directory,  recursively,  following  symbolic links only if they
254              are on the command line.  This is equivalent to the -r option.
255
256       --exclude=GLOB
257              Skip  files  whose  base  name  matches  GLOB  (using   wildcard
258              matching).   A  file-name  glob  can  use  *,  ?,  and [...]  as
259              wildcards, and \ to quote  a  wildcard  or  backslash  character
260              literally.
261
262       --exclude-from=FILE
263              Skip  files  whose  base name matches any of the file-name globs
264              read from FILE  (using  wildcard  matching  as  described  under
265              --exclude).
266
267       --exclude-dir=DIR
268              Exclude  directories  matching  the  pattern  DIR from recursive
269              searches.
270
271       -I     Process a binary file as if it did not  contain  matching  data;
272              this is equivalent to the --binary-files=without-match option.
273
274       --include=GLOB
275              Search  only  files whose base name matches GLOB (using wildcard
276              matching as described under --exclude).
277
278       -r, --recursive
279              Read all files  under  each  directory,  recursively,  following
280              symbolic  links  only  if they are on the command line.  This is
281              equivalent to the -d recurse option.
282
283       -R, --dereference-recursive
284              Read all files under each directory,  recursively.   Follow  all
285              symbolic links, unlike -r.
286
287   Other Options
288       --line-buffered
289              Use  line  buffering  on  output.   This can cause a performance
290              penalty.
291
292       -U, --binary
293              Treat the file(s) as binary.  By default, under MS-DOS  and  MS-
294              Windows,  grep  guesses the file type by looking at the contents
295              of the first 32KB read from the file.  If grep decides the  file
296              is  a  text  file, it strips the CR characters from the original
297              file contents (to make regular expressions with  ^  and  $  work
298              correctly).  Specifying -U overrules this guesswork, causing all
299              files to be read and passed to the matching mechanism  verbatim;
300              if  the  file is a text file with CR/LF pairs at the end of each
301              line, this will cause some regular expressions  to  fail.   This
302              option  has  no  effect  on  platforms other than MS-DOS and MS-
303              Windows.
304
305       -z, --null-data
306              Treat the input as a set of lines, each  terminated  by  a  zero
307              byte  (the  ASCII NUL character) instead of a newline.  Like the
308              -Z or --null option, this option can be used with commands  like
309              sort -z to process arbitrary file names.
310

REGULAR EXPRESSIONS

312       A  regular  expression  is  a  pattern that describes a set of strings.
313       Regular  expressions  are   constructed   analogously   to   arithmetic
314       expressions, by using various operators to combine smaller expressions.
315
316       grep understands three different versions of regular expression syntax:
317       “basic,” “extended” and “perl.” In GNU grep, there is no difference  in
318       available  functionality between basic and extended syntaxes.  In other
319       implementations, basic regular  expressions  are  less  powerful.   The
320       following   description   applies   to  extended  regular  expressions;
321       differences for basic regular expressions  are  summarized  afterwards.
322       Perl   regular  expressions  give  additional  functionality,  and  are
323       documented  in  pcresyntax(3)  and  pcrepattern(3),  but  may  not   be
324       available on every system.
325
326       The  fundamental building blocks are the regular expressions that match
327       a single character.  Most characters, including all letters and digits,
328       are regular expressions that match themselves.  Any meta-character with
329       special meaning may be quoted by preceding it with a backslash.
330
331       The period . matches any single character.
332
333   Character Classes and Bracket Expressions
334       A bracket expression is a list of characters enclosed by [ and  ].   It
335       matches  any  single  character in that list; if the first character of
336       the list is the caret ^ then it matches any character not in the  list.
337       For  example,  the  regular  expression [0123456789] matches any single
338       digit.
339
340       Within a  bracket  expression,  a  range  expression  consists  of  two
341       characters separated by a hyphen.  It matches any single character that
342       sorts  between  the  two  characters,  inclusive,  using  the  locale's
343       collating  sequence  and  character set.  For example, in the default C
344       locale, [a-d] is equivalent to [abcd].  Many locales sort characters in
345       dictionary   order,  and  in  these  locales  [a-d]  is  typically  not
346       equivalent to [abcd]; it might be equivalent to [aBbCcDd], for example.
347       To  obtain  the  traditional interpretation of bracket expressions, you
348       can use the C locale by setting the LC_ALL environment variable to  the
349       value C.
350
351       Finally,  certain  named  classes  of  characters are predefined within
352       bracket expressions, as follows.  Their names are self explanatory, and
353       they   are   [:alnum:],  [:alpha:],  [:cntrl:],  [:digit:],  [:graph:],
354       [:lower:], [:print:], [:punct:], [:space:], [:upper:], and  [:xdigit:].
355       For  example,  [[:alnum:]]  means  the  character  class of numbers and
356       letters in the current locale. In the C locale and ASCII character  set
357       encoding,  this is the same as [0-9A-Za-z].  (Note that the brackets in
358       these class names are part of the symbolic names, and must be  included
359       in  addition  to the brackets delimiting the bracket expression.)  Most
360       meta-characters lose their special meaning inside bracket  expressions.
361       To  include  a  literal  ]  place  it first in the list.  Similarly, to
362       include a literal ^ place it anywhere but first.  Finally, to include a
363       literal - place it last.
364
365   Anchoring
366       The caret ^ and the dollar sign $ are meta-characters that respectively
367       match the empty string at the beginning and end of a line.
368
369   The Backslash Character and Special Expressions
370       The symbols \< and \>  respectively  match  the  empty  string  at  the
371       beginning and end of a word.  The symbol \b matches the empty string at
372       the edge of a word, and \B matches the empty string provided  it's  not
373       at the edge of a word.  The symbol \w is a synonym for [_[:alnum:]] and
374       \W is a synonym for [^_[:alnum:]].
375
376   Repetition
377       A regular expression may be  followed  by  one  of  several  repetition
378       operators:
379       ?      The preceding item is optional and matched at most once.
380       *      The preceding item will be matched zero or more times.
381       +      The preceding item will be matched one or more times.
382       {n}    The preceding item is matched exactly n times.
383       {n,}   The preceding item is matched n or more times.
384       {,m}   The  preceding  item  is matched at most m times.  This is a GNU
385              extension.
386       {n,m}  The preceding item is matched at least n  times,  but  not  more
387              than m times.
388
389   Concatenation
390       Two  regular  expressions  may  be  concatenated; the resulting regular
391       expression matches any string formed by  concatenating  two  substrings
392       that respectively match the concatenated expressions.
393
394   Alternation
395       Two  regular  expressions  may  be  joined by the infix operator |; the
396       resulting  regular  expression  matches  any  string  matching   either
397       alternate expression.
398
399   Precedence
400       Repetition  takes  precedence  over  concatenation, which in turn takes
401       precedence over alternation.  A whole expression  may  be  enclosed  in
402       parentheses   to   override   these   precedence   rules   and  form  a
403       subexpression.
404
405   Back References and Subexpressions
406       The back-reference \n, where n is a single digit, matches the substring
407       previously  matched  by  the  nth  parenthesized  subexpression  of the
408       regular expression.
409
410   Basic vs Extended Regular Expressions
411       In basic regular expressions the meta-characters ?, +, {, |, (,  and  )
412       lose  their  special  meaning; instead use the backslashed versions \?,
413       \+, \{, \|, \(, and \).
414
415       Traditional egrep did not support the { meta-character, and some  egrep
416       implementations  support \{ instead, so portable scripts should avoid {
417       in grep -E patterns and should use [{] to match a literal {.
418
419       GNU grep -E attempts to support traditional usage by assuming that { is
420       not   special  if  it  would  be  the  start  of  an  invalid  interval
421       specification.  For example, the command grep -E '{1' searches for  the
422       two-character  string  {1  instead  of  reporting a syntax error in the
423       regular expression.  POSIX allows this behavior as  an  extension,  but
424       portable scripts should avoid it.
425

ENVIRONMENT VARIABLES

427       The   behavior  of  grep  is  affected  by  the  following  environment
428       variables.
429
430       The locale for category LC_foo is  specified  by  examining  the  three
431       environment  variables  LC_ALL, LC_foo, LANG, in that order.  The first
432       of these variables that is set specifies the locale.  For  example,  if
433       LC_ALL  is not set, but LC_MESSAGES is set to pt_BR, then the Brazilian
434       Portuguese locale is used for the LC_MESSAGES category.  The  C  locale
435       is  used  if none of these environment variables are set, if the locale
436       catalog is not installed, or if grep was  not  compiled  with  national
437       language support (NLS).
438
439       GREP_OPTIONS
440              This variable specifies default options to be placed in front of
441              any  explicit  options.   For  example,   if   GREP_OPTIONS   is
442              '--binary-files=without-match  --directories=skip', grep behaves
443              as  if  the   two   options   --binary-files=without-match   and
444              --directories=skip   had  been  specified  before  any  explicit
445              options.  Option specifications are separated by whitespace.   A
446              backslash  escapes  the  next  character,  so  it can be used to
447              specify an option containing whitespace or a backslash.
448
449       GREP_COLOR
450              This variable specifies the  color  used  to  highlight  matched
451              (non-empty) text.  It is deprecated in favor of GREP_COLORS, but
452              still supported.  The mt, ms, and mc capabilities of GREP_COLORS
453              have  priority  over  it.  It can only specify the color used to
454              highlight the matching non-empty text in any  matching  line  (a
455              selected  line  when the -v command-line option is omitted, or a
456              context line when -v is specified).  The default is 01;31, which
457              means  a  bold  red  foreground  text  on the terminal's default
458              background.
459
460       GREP_COLORS
461              Specifies the colors and  other  attributes  used  to  highlight
462              various  parts  of  the  output.  Its value is a colon-separated
463              list      of      capabilities      that       defaults       to
464              ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36  with  the  rv
465              and ne boolean capabilities omitted  (i.e.,  false).   Supported
466              capabilities are as follows.
467
468              sl=    SGR  substring  for  whole selected lines (i.e., matching
469                     lines when the -v command-line option is omitted, or non-
470                     matching  lines  when  -v  is specified).  If however the
471                     boolean rv capability and the -v command-line option  are
472                     both  specified,  it  applies  to  context matching lines
473                     instead.  The default  is  empty  (i.e.,  the  terminal's
474                     default color pair).
475
476              cx=    SGR substring for whole context lines (i.e., non-matching
477                     lines when the -v  command-line  option  is  omitted,  or
478                     matching  lines  when  -v  is specified).  If however the
479                     boolean rv capability and the -v command-line option  are
480                     both specified, it applies to selected non-matching lines
481                     instead.  The default  is  empty  (i.e.,  the  terminal's
482                     default color pair).
483
484              rv     Boolean  value  that reverses (swaps) the meanings of the
485                     sl= and cx= capabilities when the -v command-line  option
486                     is specified.  The default is false (i.e., the capability
487                     is omitted).
488
489              mt=01;31
490                     SGR substring for matching non-empty text in any matching
491                     line  (i.e.,  a  selected  line  when the -v command-line
492                     option  is  omitted,  or  a  context  line  when  -v   is
493                     specified).   Setting  this is equivalent to setting both
494                     ms= and mc= at once to the same value.  The default is  a
495                     bold   red   text   foreground   over  the  current  line
496                     background.
497
498              ms=01;31
499                     SGR substring for matching non-empty text in  a  selected
500                     line.  (This is only used when the -v command-line option
501                     is omitted.)  The effect  of  the  sl=  (or  cx=  if  rv)
502                     capability  remains  active  when  this  kicks  in.   The
503                     default is a bold red text foreground  over  the  current
504                     line background.
505
506              mc=01;31
507                     SGR  substring  for  matching non-empty text in a context
508                     line.  (This is only used when the -v command-line option
509                     is  specified.)   The  effect  of  the cx= (or sl= if rv)
510                     capability  remains  active  when  this  kicks  in.   The
511                     default  is  a  bold red text foreground over the current
512                     line background.
513
514              fn=35  SGR substring for file names prefixing any content  line.
515                     The  default  is  a  magenta  text  foreground  over  the
516                     terminal's default background.
517
518              ln=32  SGR substring for  line  numbers  prefixing  any  content
519                     line.   The  default  is a green text foreground over the
520                     terminal's default background.
521
522              bn=32  SGR substring for  byte  offsets  prefixing  any  content
523                     line.   The  default  is a green text foreground over the
524                     terminal's default background.
525
526              se=36  SGR substring for separators that  are  inserted  between
527                     selected  line  fields  (:), between context line fields,
528                     (-), and between groups of adjacent  lines  when  nonzero
529                     context  is  specified  (--).  The default is a cyan text
530                     foreground over the terminal's default background.
531
532              ne     Boolean value that prevents clearing to the end  of  line
533                     using  Erase  in  Line  (EL) to Right (\33[K) each time a
534                     colorized item ends.  This  is  needed  on  terminals  on
535                     which  EL  is  not  supported.  It is otherwise useful on
536                     terminals for which the  back_color_erase  (bce)  boolean
537                     terminfo  capability  does  not  apply,  when  the chosen
538                     highlight colors do not affect the background, or when EL
539                     is  too  slow or causes too much flicker.  The default is
540                     false (i.e., the capability is omitted).
541
542              Note that boolean capabilities have no  =...   part.   They  are
543              omitted (i.e., false) by default and become true when specified.
544
545              See   the   Select   Graphic  Rendition  (SGR)  section  in  the
546              documentation of the text terminal that is  used  for  permitted
547              values   and  their  meaning  as  character  attributes.   These
548              substring values are integers in decimal representation and  can
549              be  concatenated with semicolons.  grep takes care of assembling
550              the result into a  complete  SGR  sequence  (\33[...m).   Common
551              values to concatenate include 1 for bold, 4 for underline, 5 for
552              blink, 7 for inverse, 39 for default foreground color, 30 to  37
553              for  foreground  colors,  90  to 97 for 16-color mode foreground
554              colors, 38;5;0 to 38;5;255  for  88-color  and  256-color  modes
555              foreground colors, 49 for default background color, 40 to 47 for
556              background colors, 100  to  107  for  16-color  mode  background
557              colors,  and 48;5;0 to 48;5;255 for 88-color and 256-color modes
558              background colors.
559
560       LC_ALL, LC_COLLATE, LANG
561              These variables specify the locale for the LC_COLLATE  category,
562              which  determines the collating sequence used to interpret range
563              expressions like [a-z].
564
565       LC_ALL, LC_CTYPE, LANG
566              These variables specify the locale for  the  LC_CTYPE  category,
567              which  determines the type of characters, e.g., which characters
568              are whitespace.
569
570       LC_ALL, LC_MESSAGES, LANG
571              These variables specify the locale for the LC_MESSAGES category,
572              which  determines the language that grep uses for messages.  The
573              default C locale uses American English messages.
574
575       POSIXLY_CORRECT
576              If set, grep behaves as POSIX requires; otherwise, grep  behaves
577              more  like other GNU programs.  POSIX requires that options that
578              follow file names must be treated as  file  names;  by  default,
579              such  options  are permuted to the front of the operand list and
580              are treated as options.  Also, POSIX requires that  unrecognized
581              options be diagnosed as “illegal”, but since they are not really
582              against the law the default is to diagnose  them  as  “invalid”.
583              POSIXLY_CORRECT   also   disables  _N_GNU_nonoption_argv_flags_,
584              described below.
585
586       _N_GNU_nonoption_argv_flags_
587              (Here N is grep's numeric process ID.)  If the ith character  of
588              this  environment variable's value is 1, do not consider the ith
589              operand of grep to be an option, even if it appears to  be  one.
590              A  shell  can  put  this  variable  in  the environment for each
591              command it runs, specifying which operands are  the  results  of
592              file name wildcard expansion and therefore should not be treated
593              as options.  This behavior is available  only  with  the  GNU  C
594              library, and only when POSIXLY_CORRECT is not set.
595

EXIT STATUS

597       Normally,  the  exit  status  is  0  if  selected lines are found and 1
598       otherwise.  But the exit status is 2 if an error occurred,  unless  the
599       -q  or --quiet or --silent option is used and a selected line is found.
600       Note, however, that POSIX only mandates, for  programs  such  as  grep,
601       cmp, and diff, that the exit status in case of error be greater than 1;
602       it is therefore advisable, for the sake of portability,  to  use  logic
603       that  tests  for  this  general  condition  instead  of strict equality
604       with 2.
605
607       Copyright 1998-2000, 2002, 2005-2014 Free Software Foundation, Inc.
608
609       This is free software; see the source for copying conditions.  There is
610       NO  warranty;  not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
611       PURPOSE.
612

BUGS

614   Reporting Bugs
615       Email bug reports to <bug-grep@gnu.org>, a mailing list whose web  page
616       is  <http://lists.gnu.org/mailman/listinfo/bug-grep>.   grep's Savannah
617       bug tracker is located at <http://savannah.gnu.org/bugs/?group=grep>.
618
619   Known Bugs
620       Large repetition counts in the {n,m} construct may cause  grep  to  use
621       lots of memory.  In addition, certain other obscure regular expressions
622       require exponential time and space, and may cause grep to  run  out  of
623       memory.
624
625       Back-references are very slow, and may require exponential time.
626

SEE ALSO

628   Regular Manual Pages
629       awk(1),  cmp(1),  diff(1),  find(1), gzip(1), perl(1), sed(1), sort(1),
630       xargs(1), zgrep(1), read(2),  pcre(3),  pcresyntax(3),  pcrepattern(3),
631       terminfo(5), glob(7), regex(7).
632
633   POSIX Programmer's Manual Page
634       grep(1p).
635
636   TeXinfo Documentation
637       The  full  documentation  for  grep  is maintained as a TeXinfo manual,
638       which you can read at http://www.gnu.org/software/grep/manual/.  If the
639       info and grep programs are properly installed at your site, the command
640
641              info grep
642
643       should give you access to the complete manual.
644

NOTES

646       This  man  page  is maintained only fitfully; the full documentation is
647       often more up-to-date.
648
649       GNU's not Unix, but Unix is a beast; its plural form is Unixen.
650
651
652
653User Commands                    GNU grep 2.20                         GREP(1)
Impressum