1GREP(1)                          User Commands                         GREP(1)
2
3
4

NAME

6       grep, egrep, fgrep - print lines that match patterns
7

SYNOPSIS

9       grep [OPTION...] PATTERNS [FILE...]
10       grep [OPTION...] -e PATTERNS ... [FILE...]
11       grep [OPTION...] -f PATTERN_FILE ... [FILE...]
12

DESCRIPTION

14       grep  searches  for  PATTERNS  in  each  FILE.  PATTERNS is one or more
15       patterns separated by newline characters, and  grep  prints  each  line
16       that  matches a pattern.  Typically PATTERNS should be quoted when grep
17       is used in a shell command.
18
19       A FILE of “-”  stands  for  standard  input.   If  no  FILE  is  given,
20       recursive  searches  examine  the  working  directory, and nonrecursive
21       searches read standard input.
22
23       In addition, the variant programs egrep  and  fgrep  are  the  same  as
24       grep -E  and grep -F, respectively.  These variants are deprecated, but
25       are provided for backward compatibility.
26

OPTIONS

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

REGULAR EXPRESSIONS

346       A  regular  expression  is  a  pattern that describes a set of strings.
347       Regular  expressions  are   constructed   analogously   to   arithmetic
348       expressions, by using various operators to combine smaller expressions.
349
350       grep understands three different versions of regular expression syntax:
351       “basic” (BRE), “extended” (ERE) and “perl” (PCRE).  In GNU  grep  there
352       is  no difference in available functionality between basic and extended
353       syntaxes.  In other implementations, basic regular expressions are less
354       powerful.   The  following  description  applies  to  extended  regular
355       expressions; differences for basic regular expressions  are  summarized
356       afterwards.    Perl-compatible   regular  expressions  give  additional
357       functionality, and are documented in pcresyntax(3) and  pcrepattern(3),
358       but work only if PCRE is available in the system.
359
360       The  fundamental building blocks are the regular expressions that match
361       a single character.  Most characters, including all letters and digits,
362       are regular expressions that match themselves.  Any meta-character with
363       special meaning may be quoted by preceding it with a backslash.
364
365       The period . matches any single character.  It is  unspecified  whether
366       it matches an encoding error.
367
368   Character Classes and Bracket Expressions
369       A  bracket  expression is a list of characters enclosed by [ and ].  It
370       matches any single character in that list.  If the first  character  of
371       the  list is the caret ^ then it matches any character not in the list;
372       it is unspecified whether it matches an encoding error.   For  example,
373       the regular expression [0123456789] matches any single digit.
374
375       Within  a  bracket  expression,  a  range  expression  consists  of two
376       characters separated by a hyphen.  It matches any single character that
377       sorts  between  the  two  characters,  inclusive,  using  the  locale's
378       collating sequence and character set.  For example, in  the  default  C
379       locale, [a-d] is equivalent to [abcd].  Many locales sort characters in
380       dictionary  order,  and  in  these  locales  [a-d]  is  typically   not
381       equivalent to [abcd]; it might be equivalent to [aBbCcDd], for example.
382       To obtain the traditional interpretation of  bracket  expressions,  you
383       can  use the C locale by setting the LC_ALL environment variable to the
384       value C.
385
386       Finally, certain named classes  of  characters  are  predefined  within
387       bracket expressions, as follows.  Their names are self explanatory, and
388       they  are  [:alnum:],  [:alpha:],  [:blank:],   [:cntrl:],   [:digit:],
389       [:graph:],  [:lower:],  [:print:], [:punct:], [:space:], [:upper:], and
390       [:xdigit:].  For example, [[:alnum:]]  means  the  character  class  of
391       numbers  and  letters in the current locale.  In the C locale and ASCII
392       character set encoding, this is the same as  [0-9A-Za-z].   (Note  that
393       the  brackets  in these class names are part of the symbolic names, and
394       must be included in addition to the  brackets  delimiting  the  bracket
395       expression.)   Most  meta-characters  lose their special meaning inside
396       bracket expressions.  To include a literal ]  place  it  first  in  the
397       list.   Similarly,  to include a literal ^ place it anywhere but first.
398       Finally, to include a literal - place it last.
399
400   Anchoring
401       The caret ^ and the dollar sign $ are meta-characters that respectively
402       match the empty string at the beginning and end of a line.
403
404   The Backslash Character and Special Expressions
405       The  symbols  \<  and  \>  respectively  match  the empty string at the
406       beginning and end of a word.  The symbol \b matches the empty string at
407       the  edge  of a word, and \B matches the empty string provided it's not
408       at the edge of a word.  The symbol \w is a synonym for [_[:alnum:]] and
409       \W is a synonym for [^_[:alnum:]].
410
411   Repetition
412       A  regular  expression  may  be  followed  by one of several repetition
413       operators:
414       ?      The preceding item is optional and matched at most once.
415       *      The preceding item will be matched zero or more times.
416       +      The preceding item will be matched one or more times.
417       {n}    The preceding item is matched exactly n times.
418       {n,}   The preceding item is matched n or more times.
419       {,m}   The preceding item is matched at most m times.  This  is  a  GNU
420              extension.
421       {n,m}  The  preceding  item  is  matched at least n times, but not more
422              than m times.
423
424   Concatenation
425       Two regular expressions may  be  concatenated;  the  resulting  regular
426       expression  matches  any  string formed by concatenating two substrings
427       that respectively match the concatenated expressions.
428
429   Alternation
430       Two regular expressions may be joined by  the  infix  operator  |;  the
431       resulting   regular  expression  matches  any  string  matching  either
432       alternate expression.
433
434   Precedence
435       Repetition takes precedence over concatenation,  which  in  turn  takes
436       precedence  over  alternation.   A  whole expression may be enclosed in
437       parentheses  to  override   these   precedence   rules   and   form   a
438       subexpression.
439
440   Back-references and Subexpressions
441       The back-reference \n, where n is a single digit, matches the substring
442       previously matched  by  the  nth  parenthesized  subexpression  of  the
443       regular expression.
444
445   Basic vs Extended Regular Expressions
446       In  basic  regular expressions the meta-characters ?, +, {, |, (, and )
447       lose their special meaning; instead use the  backslashed  versions  \?,
448       \+, \{, \|, \(, and \).
449

EXIT STATUS

451       Normally the exit status is 0 if a line is selected, 1 if no lines were
452       selected, and 2 if an error occurred.  However, if the -q or --quiet or
453       --silent  is  used and a line is selected, the exit status is 0 even if
454       an error occurred.
455

ENVIRONMENT

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

NOTES

622       This man page is maintained only fitfully; the  full  documentation  is
623       often more up-to-date.
624
626       Copyright 1998-2000, 2002, 2005-2020 Free Software Foundation, Inc.
627
628       This is free software; see the source for copying conditions.  There is
629       NO warranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR
630       PURPOSE.
631

BUGS

633   Reporting Bugs
634       Email  bug reports to the bug-reporting address ⟨bug-grep@gnu.org⟩.  An
635       email archive ⟨https://lists.gnu.org/mailman/listinfo/bug-grep⟩  and  a
636       bug   tracker  ⟨https://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep
637       are available.
638
639   Known Bugs
640       Large repetition counts in the {n,m} construct may cause  grep  to  use
641       lots of memory.  In addition, certain other obscure regular expressions
642       require exponential time and space, and may cause grep to  run  out  of
643       memory.
644
645       Back-references are very slow, and may require exponential time.
646

EXAMPLE

648       The  following  example  outputs  the location and contents of any line
649       containing “f” and ending in “.c”, within all files in the current  di‐
650       rectory whose names contain “g” and end in “.h”.  The -n option outputs
651       line numbers, the -- argument treats  expansions  of  “*g*.h”  starting
652       with “-” as file names not options, and the empty file /dev/null causes
653       file names to be output even if only one file name happens to be of the
654       form “*g*.h”.
655
656         $ grep -n -- 'f.*\.c$' *g*.h /dev/null
657         argmatch.h:1:/* definitions and prototypes for argmatch.c
658
659       The only line that matches is line 1 of argmatch.h.  Note that the reg‐
660       ular expression syntax used in the pattern differs  from  the  globbing
661       syntax that the shell uses to match file names.
662

SEE ALSO

664   Regular Manual Pages
665       awk(1),  cmp(1),  diff(1), find(1), perl(1), sed(1), sort(1), xargs(1),
666       read(2), pcre(3), pcresyntax(3), pcrepattern(3), terminfo(5),  glob(7),
667       regex(7).
668
669   Full Documentation
670       A complete manual ⟨https://www.gnu.org/software/grep/manual/⟩ is avail‐
671       able.  If the info and grep programs are  properly  installed  at  your
672       site, the command
673
674              info grep
675
676       should give you access to the complete manual.
677
678
679
680GNU grep 3.6                      2019-12-29                           GREP(1)
Impressum