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

REGULAR EXPRESSIONS

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

EXIT STATUS

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

ENVIRONMENT

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

NOTES

596       This man page is maintained only fitfully; the  full  documentation  is
597       often more up-to-date.
598
600       Copyright 1998-2000, 2002, 2005-2022 Free Software Foundation, Inc.
601
602       This is free software; see the source for copying conditions.  There is
603       NO warranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR
604       PURPOSE.
605

BUGS

607   Reporting Bugs
608       Email  bug reports to the bug-reporting address ⟨bug-grep@gnu.org⟩.  An
609       email archive ⟨https://lists.gnu.org/mailman/listinfo/bug-grep⟩  and  a
610       bug   tracker  ⟨https://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep
611       are available.
612
613   Known Bugs
614       Large repetition counts in the {n,m} construct may cause  grep  to  use
615       lots of memory.  In addition, certain other obscure regular expressions
616       require exponential time and space, and may cause grep to  run  out  of
617       memory.
618
619       Back-references are very slow, and may require exponential time.
620

EXAMPLE

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

SEE ALSO

638   Regular Manual Pages
639       awk(1),  cmp(1),  diff(1), find(1), perl(1), sed(1), sort(1), xargs(1),
640       read(2),  pcre2(3),   pcre2syntax(3),   pcre2pattern(3),   terminfo(5),
641       glob(7), regex(7)
642
643   Full Documentation
644       A complete manual ⟨https://www.gnu.org/software/grep/manual/⟩ is avail‐
645       able.  If the info and grep programs are  properly  installed  at  your
646       site, the command
647
648              info grep
649
650       should give you access to the complete manual.
651
652
653
654GNU grep 3.8                      2019-12-29                           GREP(1)
Impressum