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

NAME

6       grep - 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

OPTIONS

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

REGULAR EXPRESSIONS

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

EXIT STATUS

439       Normally the exit status is 0 if a line is selected, 1 if no lines were
440       selected, and 2 if an error occurred.  However, if the -q or --quiet or
441       --silent is used and a line is selected, the exit status is 0  even  if
442       an error occurred.
443

ENVIRONMENT

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

NOTES

586       This  man  page  is maintained only fitfully; the full documentation is
587       often more up-to-date.
588
590       Copyright 1998-2000, 2002, 2005-2023 Free Software Foundation, Inc.
591
592       This is free software; see the source for copying conditions.  There is
593       NO  warranty;  not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
594       PURPOSE.
595

BUGS

597   Reporting Bugs
598       Email bug reports to the bug-reporting address ⟨bug-grep@gnu.org⟩.   An
599       email  archive  ⟨https://lists.gnu.org/mailman/listinfo/bug-grep⟩ and a
600       bug  tracker   ⟨https://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep
601       are available.
602
603   Known Bugs
604       Large  repetition  counts  in the {n,m} construct may cause grep to use
605       lots of memory.  In addition, certain other obscure regular expressions
606       require  exponential  time  and space, and may cause grep to run out of
607       memory.
608
609       Back-references are very slow, and may require exponential time.
610

EXAMPLE

612       The following example outputs the location and  contents  of  any  line
613       containing  “f” and ending in “.c”, within all files in the current di‐
614       rectory whose names contain “g” and end in “.h”.  The -n option outputs
615       line  numbers,  the  --  argument treats expansions of “*g*.h” starting
616       with “-” as file names not options, and the empty file /dev/null causes
617       file names to be output even if only one file name happens to be of the
618       form “*g*.h”.
619
620         $ grep -n -- 'f.*\.c$' *g*.h /dev/null
621         argmatch.h:1:/* definitions and prototypes for argmatch.c
622
623       The only line that matches is line 1 of argmatch.h.  Note that the reg‐
624       ular  expression  syntax  used in the pattern differs from the globbing
625       syntax that the shell uses to match file names.
626

SEE ALSO

628   Regular Manual Pages
629       awk(1), cmp(1), diff(1), find(1), perl(1), sed(1),  sort(1),  xargs(1),
630       read(2),   pcre2(3),   pcre2syntax(3),   pcre2pattern(3),  terminfo(5),
631       glob(7), regex(7)
632
633   Full Documentation
634       A complete manual ⟨https://www.gnu.org/software/grep/manual/⟩ is avail‐
635       able.   If  the  info  and grep programs are properly installed at your
636       site, the command
637
638              info grep
639
640       should give you access to the complete manual.
641
642
643
644GNU grep 3.11                     2019-12-29                           GREP(1)
Impressum