1 \input texinfo @c -*-texinfo-*-
5 @settitle GNU Grep @value{VERSION}
17 This manual is for @command{grep}, a pattern matching engine.
19 Copyright @copyright{} 1999-2002, 2005, 2008-2012 Free Software Foundation,
23 Permission is granted to copy, distribute and/or modify this document
24 under the terms of the GNU Free Documentation License, Version 1.3 or
25 any later version published by the Free Software Foundation; with no
26 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
27 Texts. A copy of the license is included in the section entitled
28 ``GNU Free Documentation License''.
32 @dircategory Text creation and manipulation
34 * grep: (grep). Print lines matching a pattern.
38 @title GNU Grep: Print lines matching a pattern
39 @subtitle version @value{VERSION}, @value{UPDATED}
40 @author Alain Magloire et al.
42 @vskip 0pt plus 1filll
53 @command{grep} prints lines that contain a match for a pattern.
55 This manual is for version @value{VERSION} of GNU Grep.
61 * Introduction:: Introduction.
62 * Invoking:: Command-line options, environment, exit status.
63 * Regular Expressions:: Regular Expressions.
65 * Reporting Bugs:: Reporting Bugs.
66 * Copying:: License terms for this manual.
67 * Index:: Combined index.
74 @cindex searching for a pattern
76 @command{grep} searches input files
77 for lines containing a match to a given pattern list.
78 When it finds a match in a line,
79 it copies the line to standard output (by default),
80 or produces whatever other sort of output you have requested with options.
82 Though @command{grep} expects to do the matching on text,
83 it has no limits on input line length other than available memory,
84 and it can match arbitrary characters within a line.
85 If the final byte of an input file is not a newline,
86 @command{grep} silently supplies one.
87 Since newline is also a separator for the list of patterns,
88 there is no way to match newline characters in a text.
92 @chapter Invoking @command{grep}
94 The general synopsis of the @command{grep} command line is
97 grep @var{options} @var{pattern} @var{input_file_names}
101 There can be zero or more @var{options}.
102 @var{pattern} will only be seen as such
103 (and not as an @var{input_file_name})
104 if it wasn't already specified within @var{options}
105 (by using the @samp{-e@ @var{pattern}}
106 or @samp{-f@ @var{file}} options).
107 There can be zero or more @var{input_file_names}.
110 * Command-line Options:: Short and long names, grouped by category.
111 * Environment Variables:: POSIX, GNU generic, and GNU grep specific.
112 * Exit Status:: Exit status returned by @command{grep}.
113 * grep Programs:: @command{grep} programs.
116 @node Command-line Options
117 @section Command-line Options
119 @command{grep} comes with a rich set of options:
120 some from POSIX and some being GNU extensions.
121 Long option names are always a GNU extension,
122 even for options that are from POSIX specifications.
123 Options that are specified by POSIX,
124 under their short names,
125 are explicitly marked as such
126 to facilitate POSIX-portable programming.
127 A few option names are provided
128 for compatibility with older or more exotic implementations.
131 * Generic Program Information::
133 * General Output Control::
134 * Output Line Prefix Control::
135 * Context Line Control::
136 * File and Directory Selection::
140 Several additional options control
141 which variant of the @command{grep} matching engine is used.
142 @xref{grep Programs}.
144 @node Generic Program Information
145 @subsection Generic Program Information
151 @cindex usage summary, printing
152 Print a usage message briefly summarizing the command-line options
153 and the bug-reporting address, then exit.
159 @cindex version, printing
160 Print the version number of @command{grep} to the standard output stream.
161 This version number should be included in all bug reports.
165 @node Matching Control
166 @subsection Matching Control
170 @item -e @var{pattern}
171 @itemx --regexp=@var{pattern}
173 @opindex --regexp=@var{pattern}
175 Use @var{pattern} as the pattern.
176 This can be used to specify multiple search patterns,
177 or to protect a pattern beginning with a @samp{-}.
178 (@option{-e} is specified by POSIX.)
181 @itemx --file=@var{file}
184 @cindex pattern from file
185 Obtain patterns from @var{file}, one per line.
186 The empty file contains zero patterns, and therefore matches nothing.
187 (@option{-f} is specified by POSIX.)
194 @opindex --ignore-case
195 @cindex case insensitive search
196 Ignore case distinctions in both the pattern and the input files.
197 @option{-y} is an obsolete synonym that is provided for compatibility.
198 (@option{-i} is specified by POSIX.)
201 @itemx --invert-match
203 @opindex --invert-match
204 @cindex invert matching
205 @cindex print non-matching lines
206 Invert the sense of matching, to select non-matching lines.
207 (@option{-v} is specified by POSIX.)
212 @opindex --word-regexp
213 @cindex matching whole words
214 Select only those lines containing matches that form whole words.
215 The test is that the matching substring must either
216 be at the beginning of the line,
217 or preceded by a non-word constituent character.
219 it must be either at the end of the line
220 or followed by a non-word constituent character.
221 Word-constituent characters are letters, digits, and the underscore.
226 @opindex --line-regexp
227 @cindex match the whole line
228 Select only those matches that exactly match the whole line.
229 (@option{-x} is specified by POSIX.)
233 @node General Output Control
234 @subsection General Output Control
242 @cindex counting lines
243 Suppress normal output;
244 instead print a count of matching lines for each input file.
245 With the @option{-v} (@option{--invert-match}) option,
246 count non-matching lines.
247 (@option{-c} is specified by POSIX.)
249 @item --color[=@var{WHEN}]
250 @itemx --colour[=@var{WHEN}]
253 @cindex highlight, color, colour
254 Surround the matched (non-empty) strings, matching lines, context lines,
255 file names, line numbers, byte offsets, and separators (for fields and
256 groups of context lines) with escape sequences to display them in color
258 The colors are defined by the environment variable @env{GREP_COLORS}
259 and default to @samp{ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36}
260 for bold red matched text, magenta file names, green line numbers,
261 green byte offsets, cyan separators, and default terminal colors otherwise.
262 The deprecated environment variable @env{GREP_COLOR} is still supported,
263 but its setting does not have priority;
264 it defaults to @samp{01;31} (bold red)
265 which only covers the color for matched text.
266 @var{WHEN} is @samp{never}, @samp{always}, or @samp{auto}.
269 @itemx --files-without-match
271 @opindex --files-without-match
272 @cindex files which don't match
273 Suppress normal output;
274 instead print the name of each input file from which
275 no output would normally have been printed.
276 The scanning of each file stops on the first match.
279 @itemx --files-with-matches
281 @opindex --files-with-matches
282 @cindex names of matching files
283 Suppress normal output;
284 instead print the name of each input file from which
285 output would normally have been printed.
286 The scanning of each file stops on the first match.
287 (@option{-l} is specified by POSIX.)
290 @itemx --max-count=@var{num}
294 Stop reading a file after @var{num} matching lines.
295 If the input is standard input from a regular file,
296 and @var{num} matching lines are output,
297 @command{grep} ensures that the standard input is positioned
298 just after the last matching line before exiting,
299 regardless of the presence of trailing context lines.
300 This enables a calling process to resume a search.
301 For example, the following shell script makes use of it:
304 while grep -m 1 PATTERN
310 But the following probably will not work because a pipe is not a regular
314 # This probably will not work.
316 while grep -m 1 PATTERN
322 When @command{grep} stops after @var{num} matching lines,
323 it outputs any trailing context lines.
324 Since context does not include matching lines,
325 @command{grep} will stop when it encounters another matching line.
326 When the @option{-c} or @option{--count} option is also used,
327 @command{grep} does not output a count greater than @var{num}.
328 When the @option{-v} or @option{--invert-match} option is also used,
329 @command{grep} stops after outputting @var{num} non-matching lines.
332 @itemx --only-matching
334 @opindex --only-matching
335 @cindex only matching
336 Print only the matched (non-empty) parts of matching lines,
337 with each such part on a separate output line.
345 @cindex quiet, silent
346 Quiet; do not write anything to standard output.
347 Exit immediately with zero status if any match is found,
348 even if an error was detected.
349 Also see the @option{-s} or @option{--no-messages} option.
350 (@option{-q} is specified by POSIX.)
355 @opindex --no-messages
356 @cindex suppress error messages
357 Suppress error messages about nonexistent or unreadable files.
359 unlike GNU @command{grep},
360 7th Edition Unix @command{grep} did not conform to POSIX,
361 because it lacked @option{-q}
362 and its @option{-s} option behaved like
363 GNU @command{grep}'s @option{-q} option.@footnote{Of course, 7th Edition
364 Unix predated POSIX by several years!}
365 USG-style @command{grep} also lacked @option{-q}
366 but its @option{-s} option behaved like GNU @command{grep}'s.
367 Portable shell scripts should avoid both
368 @option{-q} and @option{-s} and should redirect
369 standard and error output to @file{/dev/null} instead.
370 (@option{-s} is specified by POSIX.)
374 @node Output Line Prefix Control
375 @subsection Output Line Prefix Control
377 When several prefix fields are to be output,
378 the order is always file name, line number, and byte offset,
379 regardless of the order in which these options were specified.
386 @opindex --byte-offset
388 Print the 0-based byte offset within the input file
389 before each line of output.
390 If @option{-o} (@option{--only-matching}) is specified,
391 print the offset of the matching part itself.
392 When @command{grep} runs on MS-DOS or MS-Windows,
393 the printed byte offsets depend on whether
394 the @option{-u} (@option{--unix-byte-offsets}) option is used;
398 @itemx --with-filename
400 @opindex --with-filename
401 @cindex with filename prefix
402 Print the file name for each match.
403 This is the default when there is more than one file to search.
408 @opindex --no-filename
409 @cindex no filename prefix
410 Suppress the prefixing of file names on output.
411 This is the default when there is only one file
412 (or only standard input) to search.
414 @item --label=@var{LABEL}
416 @cindex changing name of standard input
417 Display input actually coming from standard input
418 as input coming from file @var{LABEL}. This is
419 especially useful when implementing tools like
420 @command{zgrep}; e.g.:
423 gzip -cd foo.gz | grep --label=foo -H something
429 @opindex --line-number
430 @cindex line numbering
431 Prefix each line of output with the 1-based line number within its input file.
432 (@option{-n} is specified by POSIX.)
437 @opindex --initial-tab
438 @cindex tab-aligned content lines
439 Make sure that the first character of actual line content lies on a tab stop,
440 so that the alignment of tabs looks normal.
441 This is useful with options that prefix their output to the actual content:
442 @option{-H}, @option{-n}, and @option{-b}.
443 In order to improve the probability that lines
444 from a single file will all start at the same column,
445 this also causes the line number and byte offset (if present)
446 to be printed in a minimum-size field width.
449 @itemx --unix-byte-offsets
451 @opindex --unix-byte-offsets
452 @cindex MS-DOS/MS-Windows byte offsets
453 @cindex byte offsets, on MS-DOS/MS-Windows
454 Report Unix-style byte offsets.
455 This option causes @command{grep} to report byte offsets
456 as if the file were a Unix-style text file,
457 i.e., the byte offsets ignore the @code{CR} characters that were stripped.
458 This will produce results identical
459 to running @command{grep} on a Unix machine.
460 This option has no effect unless the @option{-b} option is also used;
461 it has no effect on platforms other than MS-DOS and MS-Windows.
467 @cindex zero-terminated file names
468 Output a zero byte (the ASCII @code{NUL} character)
469 instead of the character that normally follows a file name.
471 @samp{grep -lZ} outputs a zero byte after each file name
472 instead of the usual newline.
473 This option makes the output unambiguous,
474 even in the presence of file names containing unusual characters like newlines.
475 This option can be used with commands like
476 @samp{find -print0}, @samp{perl -0}, @samp{sort -z}, and @samp{xargs -0}
477 to process arbitrary file names,
478 even those that contain newline characters.
482 @node Context Line Control
483 @subsection Context Line Control
485 Regardless of how these options are set,
486 @command{grep} will never print any given line more than once.
487 If the @option{-o} (@option{--only-matching}) option is specified,
488 these options have no effect and a warning is given upon their use.
493 @itemx --after-context=@var{num}
495 @opindex --after-context
496 @cindex after context
497 @cindex context lines, after match
498 Print @var{num} lines of trailing context after matching lines.
501 @itemx --before-context=@var{num}
503 @opindex --before-context
504 @cindex before context
505 @cindex context lines, before match
506 Print @var{num} lines of leading context before matching lines.
510 @itemx --context=@var{num}
515 Print @var{num} lines of leading and trailing output context.
517 @item --group-separator=@var{string}
518 @opindex --group-separator
519 @cindex group separator
520 When @option{-A}, @option{-B} or @option{-C} are in use,
521 print @var{string} instead of @option{--} around disjoint groups
524 @item --no-group-separator
525 @opindex --group-separator
526 @cindex group separator
527 When @option{-A}, @option{-B} or @option{-C} are in use,
528 print disjoint groups of lines adjacent to each other.
532 Here are some points about how @command{grep} chooses
533 the separator to print between prefix fields and line content:
537 Matching lines normally use @samp{:} as a separator
538 between prefix fields and actual line content.
541 Context (i.e., non-matching) lines use @samp{-} instead.
544 When no context is specified,
545 matching lines are simply output one right after another.
548 When nonzero context is specified,
549 lines that are adjacent in the input form a group
550 and are output one right after another, while
551 a separator appears by default between disjoint groups on a line
552 of its own and without any prefix.
555 The default separator
556 is @samp{--}, however whether to include it and its appearance
557 can be changed with the options above.
560 Each group may contain
561 several matching lines when they are close enough to each other
562 that two otherwise adjacent but divided groups connect
563 and can just merge into a single contiguous one.
566 @node File and Directory Selection
567 @subsection File and Directory Selection
575 @cindex suppress binary data
577 Process a binary file as if it were text;
578 this is equivalent to the @samp{--binary-files=text} option.
580 @item --binary-files=@var{type}
581 @opindex --binary-files
583 If a file's allocation metadata or its first few bytes
584 indicate that the file contains binary data,
585 assume that the file is of type @var{type}.
586 By default, @var{type} is @samp{binary},
587 and @command{grep} normally outputs either
588 a one-line message saying that a binary file matches,
589 or no message if there is no match.
591 If @var{type} is @samp{without-match},
592 @command{grep} assumes that a binary file does not match;
593 this is equivalent to the @option{-I} option.
595 If @var{type} is @samp{text},
596 @command{grep} processes a binary file as if it were text;
597 this is equivalent to the @option{-a} option.
599 @emph{Warning:} @samp{--binary-files=text} might output binary garbage,
600 which can have nasty side effects
601 if the output is a terminal and
602 if the terminal driver interprets some of it as commands.
604 @item -D @var{action}
605 @itemx --devices=@var{action}
608 @cindex device search
609 If an input file is a device, FIFO, or socket, use @var{action} to process it.
610 If @var{action} is @samp{read},
611 all devices are read just as if they were ordinary files.
612 If @var{action} is @samp{skip},
613 devices, FIFOs, and sockets are silently skipped.
614 By default, devices are read if they are on the command line or if the
615 @option{-R} (@option{--dereference-recursive}) option is used, and are
616 skipped if they are encountered recursively and the @option{-r}
617 (@option{--recursive}) option is used.
618 This option has no effect on a file that is read via standard input.
620 @item -d @var{action}
621 @itemx --directories=@var{action}
623 @opindex --directories
624 @cindex directory search
625 @cindex symbolic links
626 If an input file is a directory, use @var{action} to process it.
627 By default, @var{action} is @samp{read},
628 which means that directories are read just as if they were ordinary files
629 (some operating systems and file systems disallow this,
630 and will cause @command{grep}
631 to print error messages for every directory or silently skip them).
632 If @var{action} is @samp{skip}, directories are silently skipped.
633 If @var{action} is @samp{recurse},
634 @command{grep} reads all files under each directory, recursively,
635 following command-line symbolic links and skipping other symlinks;
636 this is equivalent to the @option{-r} option.
638 @item --exclude=@var{glob}
640 @cindex exclude files
641 @cindex searching directory trees
642 Skip files whose base name matches @var{glob}
643 (using wildcard matching).
644 A file-name glob can use
645 @samp{*}, @samp{?}, and @samp{[}...@samp{]} as wildcards,
646 and @code{\} to quote a wildcard or backslash character literally.
648 @item --exclude-from=@var{file}
649 @opindex --exclude-from
650 @cindex exclude files
651 @cindex searching directory trees
652 Skip files whose base name matches any of the file-name globs
653 read from @var{file} (using wildcard matching as described
654 under @option{--exclude}).
656 @item --exclude-dir=@var{dir}
657 @opindex --exclude-dir
658 @cindex exclude directories
659 Exclude directories matching the pattern @var{dir} from recursive
663 Process a binary file as if it did not contain matching data;
664 this is equivalent to the @samp{--binary-files=without-match} option.
666 @item --include=@var{glob}
668 @cindex include files
669 @cindex searching directory trees
670 Search only files whose base name matches @var{glob}
671 (using wildcard matching as described under @option{--exclude}).
677 @cindex recursive search
678 @cindex searching directory trees
679 @cindex symbolic links
680 For each directory operand,
681 read and process all files in that directory, recursively.
682 Follow symbolic links on the command line, but skip symlinks
683 that are encountered recursively.
684 This is the same as the @samp{--directories=recurse} option.
687 @itemx --dereference-recursive
689 @opindex --dereference-recursive
690 @cindex recursive search
691 @cindex searching directory trees
692 @cindex symbolic links
693 For each directory operand, read and process all files in that
694 directory, recursively, following all symbolic links.
699 @subsection Other Options
703 @item --line-buffered
704 @opindex --line-buffered
705 @cindex line buffering
706 Use line buffering on output.
707 This can cause a performance penalty.
711 @cindex memory mapped input
712 This option is deprecated and now elicits a warning, but is otherwise a no-op.
713 It used to make @command{grep} read
714 input with the @code{mmap} system call, instead of the default @code{read}
715 system call. On modern systems, @code{mmap} would rarely if ever yield
722 @cindex MS-DOS/MS-Windows binary files
723 @cindex binary files, MS-DOS/MS-Windows
724 Treat the file(s) as binary.
725 By default, under MS-DOS and MS-Windows,
726 @command{grep} guesses whether a file is text or binary
727 as described for the @option{--binary-files} option.
728 If @command{grep} decides the file is a text file,
729 it strips the @code{CR} characters from the original file contents
730 (to make regular expressions with @code{^} and @code{$} work correctly).
731 Specifying @option{-U} overrules this guesswork,
732 causing all files to be read and passed to the matching mechanism verbatim;
733 if the file is a text file with @code{CR/LF} pairs at the end of each line,
734 this will cause some regular expressions to fail.
735 This option has no effect
736 on platforms other than MS-DOS and MS-Windows.
742 @cindex zero-terminated lines
743 Treat the input as a set of lines, each terminated by a zero byte (the
744 ASCII @code{NUL} character) instead of a newline.
745 Like the @option{-Z} or @option{--null} option,
746 this option can be used with commands like
747 @samp{sort -z} to process arbitrary file names.
751 @node Environment Variables
752 @section Environment Variables
754 The behavior of @command{grep} is affected
755 by the following environment variables.
757 The locale for category @w{@code{LC_@var{foo}}}
758 is specified by examining the three environment variables
759 @env{LC_ALL}, @w{@env{LC_@var{foo}}}, and @env{LANG},
761 The first of these variables that is set specifies the locale.
762 For example, if @env{LC_ALL} is not set,
763 but @env{LC_MESSAGES} is set to @samp{pt_BR},
764 then the Brazilian Portuguese locale is used
765 for the @code{LC_MESSAGES} category.
766 The @samp{C} locale is used if none of these environment variables are set,
767 if the locale catalog is not installed,
768 or if @command{grep} was not compiled
769 with national language support (NLS).
771 Many of the environment variables in the following list let you
772 control highlighting using
773 Select Graphic Rendition (SGR)
774 commands interpreted by the terminal or terminal emulator.
777 in the documentation of your text terminal
778 for permitted values and their meanings as character attributes.)
779 These substring values are integers in decimal representation
780 and can be concatenated with semicolons.
781 @command{grep} takes care of assembling the result
782 into a complete SGR sequence (@samp{\33[}...@samp{m}).
783 Common values to concatenate include
785 @samp{4} for underline,
787 @samp{7} for inverse,
788 @samp{39} for default foreground color,
789 @samp{30} to @samp{37} for foreground colors,
790 @samp{90} to @samp{97} for 16-color mode foreground colors,
791 @samp{38;5;0} to @samp{38;5;255}
792 for 88-color and 256-color modes foreground colors,
793 @samp{49} for default background color,
794 @samp{40} to @samp{47} for background colors,
795 @samp{100} to @samp{107} for 16-color mode background colors,
796 and @samp{48;5;0} to @samp{48;5;255}
797 for 88-color and 256-color modes background colors.
799 The two-letter names used in the @env{GREP_COLORS} environment variable
800 (and some of the others) refer to terminal ``capabilities,'' the ability
801 of a terminal to highlight text, or change its color, and so on.
802 These capabilities are stored in an online database and accessed by
803 the @code{terminfo} library.
805 @cindex environment variables
810 @vindex GREP_OPTIONS @r{environment variable}
811 @cindex default options environment variable
812 This variable specifies default options to be placed in front of any
814 For example, if @code{GREP_OPTIONS} is
815 @samp{--binary-files=without-match --directories=skip}, @command{grep}
816 behaves as if the two options @samp{--binary-files=without-match} and
817 @samp{--directories=skip} had been specified before
818 any explicit options.
819 Option specifications are separated by
821 A backslash escapes the next character, so it can be used to
822 specify an option containing whitespace or a backslash.
824 The @code{GREP_OPTIONS} value does not affect whether @command{grep}
825 without file operands searches standard input or the working
826 directory; that is affected only by command-line options. For
827 example, the command @samp{grep PAT} searches standard input and the
828 command @samp{grep -r PAT} searches the working directory, regardless
829 of whether @code{GREP_OPTIONS} contains @option{-r}.
832 @vindex GREP_COLOR @r{environment variable}
833 @cindex highlight markers
834 This variable specifies the color used to highlight matched (non-empty) text.
835 It is deprecated in favor of @env{GREP_COLORS}, but still supported.
836 The @samp{mt}, @samp{ms}, and @samp{mc} capabilities of @env{GREP_COLORS}
837 have priority over it.
838 It can only specify the color used to highlight
839 the matching non-empty text in any matching line
840 (a selected line when the @option{-v} command-line option is omitted,
841 or a context line when @option{-v} is specified).
842 The default is @samp{01;31},
843 which means a bold red foreground text on the terminal's default background.
846 @vindex GREP_COLORS @r{environment variable}
847 @cindex highlight markers
848 This variable specifies the colors and other attributes
849 used to highlight various parts of the output.
850 Its value is a colon-separated list of @code{terminfo} capabilities
851 that defaults to @samp{ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36}
852 with the @samp{rv} and @samp{ne} boolean capabilities omitted (i.e., false).
853 Supported capabilities are as follows.
857 @vindex sl GREP_COLORS @r{capability}
858 SGR substring for whole selected lines
860 matching lines when the @option{-v} command-line option is omitted,
861 or non-matching lines when @option{-v} is specified).
862 If however the boolean @samp{rv} capability
863 and the @option{-v} command-line option are both specified,
864 it applies to context matching lines instead.
865 The default is empty (i.e., the terminal's default color pair).
868 @vindex cx GREP_COLORS @r{capability}
869 SGR substring for whole context lines
871 non-matching lines when the @option{-v} command-line option is omitted,
872 or matching lines when @option{-v} is specified).
873 If however the boolean @samp{rv} capability
874 and the @option{-v} command-line option are both specified,
875 it applies to selected non-matching lines instead.
876 The default is empty (i.e., the terminal's default color pair).
879 @vindex rv GREP_COLORS @r{capability}
880 Boolean value that reverses (swaps) the meanings of
881 the @samp{sl=} and @samp{cx=} capabilities
882 when the @option{-v} command-line option is specified.
883 The default is false (i.e., the capability is omitted).
886 @vindex mt GREP_COLORS @r{capability}
887 SGR substring for matching non-empty text in any matching line
889 a selected line when the @option{-v} command-line option is omitted,
890 or a context line when @option{-v} is specified).
891 Setting this is equivalent to setting both @samp{ms=} and @samp{mc=}
892 at once to the same value.
893 The default is a bold red text foreground over the current line background.
896 @vindex ms GREP_COLORS @r{capability}
897 SGR substring for matching non-empty text in a selected line.
898 (This is used only when the @option{-v} command-line option is omitted.)
899 The effect of the @samp{sl=} (or @samp{cx=} if @samp{rv}) capability
900 remains active when this takes effect.
901 The default is a bold red text foreground over the current line background.
904 @vindex mc GREP_COLORS @r{capability}
905 SGR substring for matching non-empty text in a context line.
906 (This is used only when the @option{-v} command-line option is specified.)
907 The effect of the @samp{cx=} (or @samp{sl=} if @samp{rv}) capability
908 remains active when this takes effect.
909 The default is a bold red text foreground over the current line background.
912 @vindex fn GREP_COLORS @r{capability}
913 SGR substring for file names prefixing any content line.
914 The default is a magenta text foreground over the terminal's default background.
917 @vindex ln GREP_COLORS @r{capability}
918 SGR substring for line numbers prefixing any content line.
919 The default is a green text foreground over the terminal's default background.
922 @vindex bn GREP_COLORS @r{capability}
923 SGR substring for byte offsets prefixing any content line.
924 The default is a green text foreground over the terminal's default background.
927 @vindex fn GREP_COLORS @r{capability}
928 SGR substring for separators that are inserted
929 between selected line fields (@samp{:}),
930 between context line fields (@samp{-}),
931 and between groups of adjacent lines
932 when nonzero context is specified (@samp{--}).
933 The default is a cyan text foreground over the terminal's default background.
936 @vindex ne GREP_COLORS @r{capability}
937 Boolean value that prevents clearing to the end of line
938 using Erase in Line (EL) to Right (@samp{\33[K})
939 each time a colorized item ends.
940 This is needed on terminals on which EL is not supported.
941 It is otherwise useful on terminals
942 for which the @code{back_color_erase}
943 (@code{bce}) boolean @code{terminfo} capability does not apply,
944 when the chosen highlight colors do not affect the background,
945 or when EL is too slow or causes too much flicker.
946 The default is false (i.e., the capability is omitted).
949 Note that boolean capabilities have no @samp{=}... part.
950 They are omitted (i.e., false) by default and become true when specified.
956 @vindex LC_ALL @r{environment variable}
957 @vindex LC_COLLATE @r{environment variable}
958 @vindex LANG @r{environment variable}
959 @cindex character type
960 @cindex national language support
962 These variables specify the locale for the @code{LC_COLLATE} category,
963 which determines the collating sequence
964 used to interpret range expressions like @samp{[a-z]}.
969 @vindex LC_ALL @r{environment variable}
970 @vindex LC_CTYPE @r{environment variable}
971 @vindex LANG @r{environment variable}
972 These variables specify the locale for the @code{LC_CTYPE} category,
973 which determines the type of characters,
974 e.g., which characters are whitespace.
979 @vindex LC_ALL @r{environment variable}
980 @vindex LC_MESSAGES @r{environment variable}
981 @vindex LANG @r{environment variable}
982 @cindex language of messages
983 @cindex message language
984 @cindex national language support
985 @cindex translation of message language
986 These variables specify the locale for the @code{LC_MESSAGES} category,
987 which determines the language that @command{grep} uses for messages.
988 The default @samp{C} locale uses American English messages.
990 @item POSIXLY_CORRECT
991 @vindex POSIXLY_CORRECT @r{environment variable}
992 If set, @command{grep} behaves as POSIX requires; otherwise,
993 @command{grep} behaves more like other GNU programs.
995 requires that options that
996 follow file names must be treated as file names;
998 such options are permuted to the front of the operand list
999 and are treated as options.
1000 Also, @code{POSIXLY_CORRECT} disables special handling of an
1001 invalid bracket expression. @xref{invalid-bracket-expr}.
1003 @item _@var{N}_GNU_nonoption_argv_flags_
1004 @vindex _@var{N}_GNU_nonoption_argv_flags_ @r{environment variable}
1005 (Here @code{@var{N}} is @command{grep}'s numeric process ID.)
1006 If the @var{i}th character of this environment variable's value is @samp{1},
1007 do not consider the @var{i}th operand of @command{grep} to be an option,
1008 even if it appears to be one.
1009 A shell can put this variable in the environment for each command it runs,
1010 specifying which operands are the results of file name wildcard expansion
1011 and therefore should not be treated as options.
1012 This behavior is available only with the GNU C library,
1013 and only when @code{POSIXLY_CORRECT} is not set.
1019 @section Exit Status
1021 @cindex return status
1023 Normally, the exit status is 0 if selected lines are found and 1 otherwise.
1024 But the exit status is 2 if an error occurred, unless the @option{-q} or
1025 @option{--quiet} or @option{--silent} option is used and a selected line
1027 Note, however, that POSIX only mandates,
1028 for programs such as @command{grep}, @command{cmp}, and @command{diff},
1029 that the exit status in case of error be greater than 1;
1030 it is therefore advisable, for the sake of portability,
1031 to use logic that tests for this general condition
1032 instead of strict equality with@ 2.
1036 @section @command{grep} Programs
1037 @cindex @command{grep} programs
1038 @cindex variants of @command{grep}
1040 @command{grep} searches the named input files
1041 for lines containing a match to the given pattern.
1042 By default, @command{grep} prints the matching lines.
1043 A file named @file{-} stands for standard input.
1044 If no input is specified, @command{grep} searches the working
1045 directory @file{.} if given a command-line option specifying
1046 recursion; otherwise, @command{grep} searches standard input.
1047 There are four major variants of @command{grep},
1048 controlled by the following options.
1053 @itemx --basic-regexp
1055 @opindex --basic-regexp
1056 @cindex matching basic regular expressions
1057 Interpret the pattern as a basic regular expression (BRE).
1058 This is the default.
1061 @itemx --extended-regexp
1063 @opindex --extended-regexp
1064 @cindex matching extended regular expressions
1065 Interpret the pattern as an extended regular expression (ERE).
1066 (@option{-E} is specified by POSIX.)
1069 @itemx --fixed-strings
1071 @opindex --fixed-strings
1072 @cindex matching fixed strings
1073 Interpret the pattern as a list of fixed strings, separated
1074 by newlines, any of which is to be matched.
1075 (@option{-F} is specified by POSIX.)
1078 @itemx --perl-regexp
1080 @opindex --perl-regexp
1081 @cindex matching Perl regular expressions
1082 Interpret the pattern as a Perl regular expression.
1083 This is highly experimental and
1084 @samp{grep@ -P} may warn of unimplemented features.
1089 two variant programs @command{egrep} and @command{fgrep} are available.
1090 @command{egrep} is the same as @samp{grep@ -E}.
1091 @command{fgrep} is the same as @samp{grep@ -F}.
1092 Direct invocation as either
1093 @command{egrep} or @command{fgrep} is deprecated,
1094 but is provided to allow historical applications
1095 that rely on them to run unmodified.
1098 @node Regular Expressions
1099 @chapter Regular Expressions
1100 @cindex regular expressions
1102 A @dfn{regular expression} is a pattern that describes a set of strings.
1103 Regular expressions are constructed analogously to arithmetic expressions,
1104 by using various operators to combine smaller expressions.
1105 @command{grep} understands
1106 three different versions of regular expression syntax:
1107 ``basic,'' (BRE) ``extended'' (ERE) and ``perl''.
1108 In GNU @command{grep},
1109 there is no difference in available functionality between the basic and
1111 In other implementations, basic regular expressions are less powerful.
1112 The following description applies to extended regular expressions;
1113 differences for basic regular expressions are summarized afterwards.
1114 Perl regular expressions give additional functionality, and are
1115 documented in the @i{pcresyntax}(3) and @i{pcrepattern}(3) manual pages,
1116 but may not be available on every system.
1119 * Fundamental Structure::
1120 * Character Classes and Bracket Expressions::
1121 * The Backslash Character and Special Expressions::
1123 * Back-references and Subexpressions::
1124 * Basic vs Extended::
1127 @node Fundamental Structure
1128 @section Fundamental Structure
1130 The fundamental building blocks are the regular expressions that match
1132 Most characters, including all letters and digits,
1133 are regular expressions that match themselves.
1135 with special meaning may be quoted by preceding it with a backslash.
1137 A regular expression may be followed by one of several
1138 repetition operators:
1146 The period @samp{.} matches any single character.
1150 @cindex question mark
1151 @cindex match expression at most once
1152 The preceding item is optional and will be matched at most once.
1157 @cindex match expression zero or more times
1158 The preceding item will be matched zero or more times.
1163 @cindex match expression one or more times
1164 The preceding item will be matched one or more times.
1167 @opindex @{@var{n}@}
1168 @cindex braces, one argument
1169 @cindex match expression @var{n} times
1170 The preceding item is matched exactly @var{n} times.
1173 @opindex @{@var{n},@}
1174 @cindex braces, second argument omitted
1175 @cindex match expression @var{n} or more times
1176 The preceding item is matched @var{n} or more times.
1179 @opindex @{,@var{m}@}
1180 @cindex braces, first argument omitted
1181 @cindex match expression at most @var{m} times
1182 The preceding item is matched at most @var{m} times.
1184 @item @{@var{n},@var{m}@}
1185 @opindex @{@var{n},@var{m}@}
1186 @cindex braces, two arguments
1187 @cindex match expression from @var{n} to @var{m} times
1188 The preceding item is matched at least @var{n} times, but not more than
1193 The empty regular expression matches the empty string.
1194 Two regular expressions may be concatenated;
1195 the resulting regular expression
1196 matches any string formed by concatenating two substrings
1197 that respectively match the concatenated expressions.
1199 Two regular expressions may be joined by the infix operator @samp{|};
1200 the resulting regular expression
1201 matches any string matching either alternate expression.
1203 Repetition takes precedence over concatenation,
1204 which in turn takes precedence over alternation.
1205 A whole expression may be enclosed in parentheses
1206 to override these precedence rules and form a subexpression.
1208 @node Character Classes and Bracket Expressions
1209 @section Character Classes and Bracket Expressions
1211 @cindex bracket expression
1212 @cindex character class
1213 A @dfn{bracket expression} is a list of characters enclosed by @samp{[} and
1215 It matches any single character in that list;
1216 if the first character of the list is the caret @samp{^},
1217 then it matches any character @strong{not} in the list.
1218 For example, the regular expression
1219 @samp{[0123456789]} matches any single digit.
1221 @cindex range expression
1222 Within a bracket expression, a @dfn{range expression} consists of two
1223 characters separated by a hyphen.
1224 It matches any single character that
1225 sorts between the two characters, inclusive, using the locale's
1226 collating sequence and character set.
1227 For example, in the default C
1228 locale, @samp{[a-d]} is equivalent to @samp{[abcd]}.
1230 characters in dictionary order, and in these locales @samp{[a-d]} is
1231 typically not equivalent to @samp{[abcd]};
1232 it might be equivalent to @samp{[aBbCcDd]}, for example.
1233 To obtain the traditional interpretation
1234 of bracket expressions, you can use the @samp{C} locale by setting the
1235 @env{LC_ALL} environment variable to the value @samp{C}.
1237 Finally, certain named classes of characters are predefined within
1238 bracket expressions, as follows.
1239 Their interpretation depends on the @code{LC_CTYPE} locale;
1240 for example, @samp{[[:alnum:]]} means the character class of numbers and letters
1241 in the current locale.
1243 @cindex classes of characters
1244 @cindex character classes
1248 @opindex alnum @r{character class}
1249 @cindex alphanumeric characters
1250 Alphanumeric characters:
1251 @samp{[:alpha:]} and @samp{[:digit:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[0-9A-Za-z]}.
1254 @opindex alpha @r{character class}
1255 @cindex alphabetic characters
1256 Alphabetic characters:
1257 @samp{[:lower:]} and @samp{[:upper:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[A-Za-z]}.
1260 @opindex blank @r{character class}
1261 @cindex blank characters
1266 @opindex cntrl @r{character class}
1267 @cindex control characters
1269 In ASCII, these characters have octal codes 000
1270 through 037, and 177 (@code{DEL}).
1271 In other character sets, these are
1272 the equivalent characters, if any.
1275 @opindex digit @r{character class}
1276 @cindex digit characters
1277 @cindex numeric characters
1278 Digits: @code{0 1 2 3 4 5 6 7 8 9}.
1281 @opindex graph @r{character class}
1282 @cindex graphic characters
1283 Graphical characters:
1284 @samp{[:alnum:]} and @samp{[:punct:]}.
1287 @opindex lower @r{character class}
1288 @cindex lower-case letters
1289 Lower-case letters; in the @samp{C} locale and ASCII character
1291 @code{a b c d e f g h i j k l m n o p q r s t u v w x y z}.
1294 @opindex print @r{character class}
1295 @cindex printable characters
1296 Printable characters:
1297 @samp{[:alnum:]}, @samp{[:punct:]}, and space.
1300 @opindex punct @r{character class}
1301 @cindex punctuation characters
1302 Punctuation characters; in the @samp{C} locale and ASCII character
1304 @code{!@: " # $ % & ' ( ) * + , - .@: / : ; < = > ?@: @@ [ \ ] ^ _ ` @{ | @} ~}.
1307 @opindex space @r{character class}
1308 @cindex space characters
1309 @cindex whitespace characters
1310 Space characters: in the @samp{C} locale, this is
1311 tab, newline, vertical tab, form feed, carriage return, and space.
1312 @xref{Usage}, for more discussion of matching newlines.
1315 @opindex upper @r{character class}
1316 @cindex upper-case letters
1317 Upper-case letters: in the @samp{C} locale and ASCII character
1319 @code{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}.
1322 @opindex xdigit @r{character class}
1323 @cindex xdigit class
1324 @cindex hexadecimal digits
1326 @code{0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f}.
1329 Note that the brackets in these class names are
1330 part of the symbolic names, and must be included in addition to
1331 the brackets delimiting the bracket expression.
1333 @anchor{invalid-bracket-expr}
1334 If you mistakenly omit the outer brackets, and search for say, @samp{[:upper:]},
1335 GNU @command{grep} prints a diagnostic and exits with status 2, on
1336 the assumption that you did not intend to search for the nominally
1337 equivalent regular expression: @samp{[:epru]}.
1338 Set the @code{POSIXLY_CORRECT} environment variable to disable this feature.
1340 Most meta-characters lose their special meaning inside bracket expressions.
1344 ends the bracket expression if it's not the first list item.
1345 So, if you want to make the @samp{]} character a list item,
1346 you must put it first.
1349 represents the open collating symbol.
1352 represents the close collating symbol.
1355 represents the open equivalence class.
1358 represents the close equivalence class.
1361 represents the open character class symbol, and should be followed by a valid character class name.
1364 represents the close character class symbol.
1367 represents the range if it's not first or last in a list or the ending point
1371 represents the characters not in the list.
1372 If you want to make the @samp{^}
1373 character a list item, place it anywhere but first.
1377 @node The Backslash Character and Special Expressions
1378 @section The Backslash Character and Special Expressions
1381 The @samp{\} character,
1382 when followed by certain ordinary characters,
1383 takes a special meaning:
1388 Match the empty string at the edge of a word.
1391 Match the empty string provided it's not at the edge of a word.
1394 Match the empty string at the beginning of word.
1397 Match the empty string at the end of word.
1400 Match word constituent, it is a synonym for @samp{[_[:alnum:]]}.
1403 Match non-word constituent, it is a synonym for @samp{[^_[:alnum:]]}.
1406 Match whitespace, it is a synonym for @samp{[[:space:]]}.
1409 Match non-whitespace, it is a synonym for @samp{[^[:space:]]}.
1413 For example, @samp{\brat\b} matches the separate word @samp{rat},
1414 @samp{\Brat\B} matches @samp{crate} but not @samp{furry rat}.
1420 The caret @samp{^} and the dollar sign @samp{$} are meta-characters that
1421 respectively match the empty string at the beginning and end of a line.
1422 They are termed @dfn{anchors}, since they force the match to be ``anchored''
1423 to beginning or end of a line, respectively.
1425 @node Back-references and Subexpressions
1426 @section Back-references and Subexpressions
1427 @cindex subexpression
1428 @cindex back-reference
1430 The back-reference @samp{\@var{n}}, where @var{n} is a single digit, matches
1431 the substring previously matched by the @var{n}th parenthesized subexpression
1432 of the regular expression.
1433 For example, @samp{(a)\1} matches @samp{aa}.
1434 When used with alternation, if the group does not participate in the match then
1435 the back-reference makes the whole match fail.
1436 For example, @samp{a(.)|b\1}
1437 will not match @samp{ba}.
1438 When multiple regular expressions are given with
1439 @option{-e} or from a file (@samp{-f @var{file}}),
1440 back-references are local to each expression.
1442 @node Basic vs Extended
1443 @section Basic vs Extended Regular Expressions
1444 @cindex basic regular expressions
1446 In basic regular expressions the meta-characters @samp{?}, @samp{+},
1447 @samp{@{}, @samp{|}, @samp{(}, and @samp{)} lose their special meaning;
1448 instead use the backslashed versions @samp{\?}, @samp{\+}, @samp{\@{},
1449 @samp{\|}, @samp{\(}, and @samp{\)}.
1451 @cindex interval specifications
1452 Traditional @command{egrep} did not support the @samp{@{} meta-character,
1453 and some @command{egrep} implementations support @samp{\@{} instead, so
1454 portable scripts should avoid @samp{@{} in @samp{grep@ -E} patterns and
1455 should use @samp{[@{]} to match a literal @samp{@{}.
1457 GNU @command{grep@ -E} attempts to support traditional usage by
1458 assuming that @samp{@{} is not special if it would be the start of an
1459 invalid interval specification.
1460 For example, the command
1461 @samp{grep@ -E@ '@{1'} searches for the two-character string @samp{@{1}
1462 instead of reporting a syntax error in the regular expression.
1463 POSIX allows this behavior as an extension, but portable scripts
1470 @cindex usage, examples
1471 Here is an example command that invokes GNU @command{grep}:
1474 grep -i 'hello.*world' menu.h main.c
1478 This lists all lines in the files @file{menu.h} and @file{main.c} that
1479 contain the string @samp{hello} followed by the string @samp{world};
1480 this is because @samp{.*} matches zero or more characters within a line.
1481 @xref{Regular Expressions}.
1482 The @option{-i} option causes @command{grep}
1483 to ignore case, causing it to match the line @samp{Hello, world!}, which
1484 it would not otherwise match.
1485 @xref{Invoking}, for more details about
1486 how to invoke @command{grep}.
1488 @cindex using @command{grep}, Q&A
1489 @cindex FAQ about @command{grep} usage
1490 Here are some common questions and answers about @command{grep} usage.
1495 How can I list just the names of matching files?
1502 lists the names of all C files in the current directory whose contents
1503 mention @samp{main}.
1506 How do I search directories recursively?
1509 grep -r 'hello' /home/gigi
1513 searches for @samp{hello} in all files
1514 under the @file{/home/gigi} directory.
1515 For more control over which files are searched,
1516 use @command{find}, @command{grep}, and @command{xargs}.
1517 For example, the following command searches only C files:
1520 find /home/gigi -name '*.c' -print0 | xargs -0r grep -H 'hello'
1523 This differs from the command:
1529 which merely looks for @samp{hello} in all files in the current
1530 directory whose names end in @samp{.c}.
1531 The @samp{find ...} command line above is more similar to the command:
1534 grep -rH --include='*.c' 'hello' /home/gigi
1538 What if a pattern has a leading @samp{-}?
1541 grep -e '--cut here--' *
1545 searches for all lines matching @samp{--cut here--}.
1546 Without @option{-e},
1547 @command{grep} would attempt to parse @samp{--cut here--} as a list of
1551 Suppose I want to search for a whole word, not a part of a word?
1558 searches only for instances of @samp{hello} that are entire words;
1559 it does not match @samp{Othello}.
1560 For more control, use @samp{\<} and
1561 @samp{\>} to match the start and end of words.
1569 searches only for words ending in @samp{hello}, so it matches the word
1573 How do I output context around the matching lines?
1580 prints two lines of context around each matching line.
1583 How do I force @command{grep} to print the name of the file?
1585 Append @file{/dev/null}:
1588 grep 'eli' /etc/passwd /dev/null
1594 /etc/passwd:eli:x:2098:1000:Eli Smith:/home/eli:/bin/bash
1597 Alternatively, use @option{-H}, which is a GNU extension:
1600 grep -H 'eli' /etc/passwd
1604 Why do people use strange regular expressions on @command{ps} output?
1607 ps -ef | grep '[c]ron'
1610 If the pattern had been written without the square brackets, it would
1611 have matched not only the @command{ps} output line for @command{cron},
1612 but also the @command{ps} output line for @command{grep}.
1613 Note that on some platforms,
1614 @command{ps} limits the output to the width of the screen;
1615 @command{grep} does not have any limit on the length of a line
1616 except the available memory.
1619 Why does @command{grep} report ``Binary file matches''?
1621 If @command{grep} listed all matching ``lines'' from a binary file, it
1622 would probably generate output that is not useful, and it might even
1623 muck up your display.
1624 So GNU @command{grep} suppresses output from
1625 files that appear to be binary files.
1626 To force GNU @command{grep}
1627 to output lines even from files that appear to be binary, use the
1628 @option{-a} or @samp{--binary-files=text} option.
1630 ``Binary file matches'' messages, use the @option{-I} or
1631 @samp{--binary-files=without-match} option.
1634 Why doesn't @samp{grep -lv} print non-matching file names?
1636 @samp{grep -lv} lists the names of all files containing one or more
1637 lines that do not match.
1638 To list the names of all files that contain no
1639 matching lines, use the @option{-L} or @option{--files-without-match}
1643 I can do ``OR'' with @samp{|}, but what about ``AND''?
1646 grep 'paul' /etc/motd | grep 'franc,ois'
1650 finds all lines that contain both @samp{paul} and @samp{franc,ois}.
1653 Why does the empty pattern match every input line?
1655 The @command{grep} command searches for lines that contain strings
1656 that match a pattern. Every line contains the empty string, so an
1657 empty pattern causes @command{grep} to find a match on each line. It
1658 is not the only such pattern: @samp{^}, @samp{$}, @samp{.*}, and many
1659 other patterns cause @command{grep} to match every line.
1661 To match empty lines, use the pattern @samp{^$}. To match blank
1662 lines, use the pattern @samp{^[[:blank:]]*$}. To match no lines at
1663 all, use the command @samp{grep -f /dev/null}.
1666 How can I search in both standard input and in files?
1668 Use the special file name @samp{-}:
1671 cat /etc/passwd | grep 'alain' - /etc/motd
1676 How to express palindromes in a regular expression?
1678 It can be done by using back-references;
1680 a palindrome of 4 characters can be written with a BRE:
1683 grep -w -e '\(.\)\(.\).\2\1' file
1686 It matches the word ``radar'' or ``civic.''
1688 Guglielmo Bondioni proposed a single RE
1689 that finds all palindromes up to 19 characters long
1690 using @w{9 subexpressions} and @w{9 back-references}:
1693 grep -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' file
1696 Note this is done by using GNU ERE extensions;
1697 it might not be portable to other implementations of @command{grep}.
1700 Why is this back-reference failing?
1703 echo 'ba' | grep -E '(a)\1|b\1'
1706 This gives no output, because the first alternate @samp{(a)\1} does not match,
1707 as there is no @samp{aa} in the input, so the @samp{\1} in the second alternate
1708 has nothing to refer back to, meaning it will never match anything.
1709 (The second alternate in this example can only match
1710 if the first alternate has matched---making the second one superfluous.)
1713 How can I match across lines?
1715 Standard grep cannot do this, as it is fundamentally line-based.
1716 Therefore, merely using the @code{[:space:]} character class does not
1717 match newlines in the way you might expect. However, if your grep is
1718 compiled with Perl patterns enabled, the Perl @samp{s}
1719 modifier (which makes @code{.} match newlines) can be used:
1722 printf 'foo\nbar\n' | grep -P '(?s)foo.*?bar'
1725 With the GNU @command{grep} option @code{-z} (@pxref{File and
1726 Directory Selection}), the input is terminated by null bytes. Thus,
1727 you can match newlines in the input, but the output will be the whole
1728 file, so this is really only useful to determine if the pattern is
1732 printf 'foo\nbar\n' | grep -z -q 'foo[[:space:]]\+bar'
1735 Failing either of those options, you need to transform the input
1736 before giving it to @command{grep}, or turn to @command{awk},
1737 @command{sed}, @command{perl}, or many other utilities that are
1738 designed to operate across lines.
1741 What do @command{grep}, @command{fgrep}, and @command{egrep} stand for?
1743 The name @command{grep} comes from the way line editing was done on Unix.
1745 @command{ed} uses the following syntax
1746 to print a list of matching lines on the screen:
1749 global/regular expression/print
1753 @command{fgrep} stands for Fixed @command{grep};
1754 @command{egrep} stands for Extended @command{grep}.
1759 @node Reporting Bugs
1760 @chapter Reporting bugs
1762 @cindex bugs, reporting
1763 Email bug reports to @email{bug-grep@@gnu.org},
1764 a mailing list whose web page is
1765 @url{http://lists.gnu.org/mailman/listinfo/bug-grep}.
1766 The Savannah bug tracker for @command{grep} is located at
1767 @url{http://savannah.gnu.org/bugs/?group=grep}.
1772 Large repetition counts in the @samp{@{n,m@}} construct may cause
1773 @command{grep} to use lots of memory.
1774 In addition, certain other
1775 obscure regular expressions require exponential time and
1776 space, and may cause @command{grep} to run out of memory.
1778 Back-references are very slow, and may require exponential time.
1785 GNU @command{grep} is licensed under the GNU GPL, which makes it @dfn{free
1788 The ``free'' in ``free software'' refers to liberty, not price. As
1789 some GNU project advocates like to point out, think of ``free speech''
1790 rather than ``free beer''. In short, you have the right (freedom) to
1791 run and change @command{grep} and distribute it to other people, and---if you
1792 want---charge money for doing either. The important restriction is
1793 that you have to grant your recipients the same rights and impose the
1796 This general method of licensing software is sometimes called
1797 @dfn{open source}. The GNU project prefers the term ``free software''
1798 for reasons outlined at
1799 @url{http://www.gnu.org/philosophy/open-source-misses-the-point.html}.
1801 This manual is free documentation in the same sense. The
1802 documentation license is included below. The license for the program
1803 is available with the source code, or at
1804 @url{http://www.gnu.org/licenses/gpl.html}.
1807 * GNU Free Documentation License::
1810 @node GNU Free Documentation License
1811 @section GNU Free Documentation License