Blame doc/grep.in.1

Packit 709fb3
.\" GNU grep man page
Packit 709fb3
.if !\n(.g \{\
Packit 709fb3
.	if !\w|\*(lq| \{\
Packit 709fb3
.		ds lq ``
Packit 709fb3
.		if \w'\(lq' .ds lq "\(lq
Packit 709fb3
.	\}
Packit 709fb3
.	if !\w|\*(rq| \{\
Packit 709fb3
.		ds rq ''
Packit 709fb3
.		if \w'\(rq' .ds rq "\(rq
Packit 709fb3
.	\}
Packit 709fb3
.\}
Packit 709fb3
.
Packit 709fb3
.ie \n[.g] .mso www.tmac
Packit 709fb3
.el \{\
Packit 709fb3
. de MTO
Packit 709fb3
\\$2 \(laemail: \\$1 \(ra\\$3
Packit 709fb3
..
Packit 709fb3
. de URL
Packit 709fb3
\\$2 \(laURL: \\$1 \(ra\\$3
Packit 709fb3
..
Packit 709fb3
.\}
Packit 709fb3
.
Packit 709fb3
.TH GREP 1 \*(Dt "GNU grep @VERSION@" "User Commands"
Packit 709fb3
.hy 0
Packit 709fb3
.
Packit 709fb3
.SH NAME
Packit 709fb3
grep, egrep, fgrep \- print lines matching a pattern
Packit 709fb3
.
Packit 709fb3
.SH SYNOPSIS
Packit 709fb3
.B grep
Packit 709fb3
.RI [ OPTIONS ]
Packit 709fb3
.I PATTERN
Packit 709fb3
.RI [ FILE .\|.\|.]
Packit 709fb3
.br
Packit 709fb3
.B grep
Packit 709fb3
.RI [ OPTIONS ]
Packit 709fb3
.B \-e
Packit 709fb3
.I PATTERN
Packit 709fb3
\&.\|.\|.\&
Packit 709fb3
.RI [ FILE .\|.\|.]
Packit 709fb3
.br
Packit 709fb3
.B grep
Packit 709fb3
.RI [ OPTIONS ]
Packit 709fb3
.B \-f
Packit 709fb3
.I FILE
Packit 709fb3
\&.\|.\|.\&
Packit 709fb3
.RI [ FILE .\|.\|.]
Packit 709fb3
.
Packit 709fb3
.SH DESCRIPTION
Packit 709fb3
.B grep
Packit 709fb3
searches for
Packit 709fb3
.I PATTERN
Packit 709fb3
in each
Packit 709fb3
.IR FILE .
Packit 709fb3
A
Packit 709fb3
.I FILE
Packit 709fb3
of
Packit 709fb3
.RB "\*(lq" \- "\*(rq"
Packit 709fb3
stands for standard input.
Packit 709fb3
If no
Packit 709fb3
.I FILE
Packit 709fb3
is given, recursive searches examine the working directory,
Packit 709fb3
and nonrecursive searches read standard input.
Packit 709fb3
By default,
Packit 709fb3
.B grep
Packit 709fb3
prints the matching lines.
Packit 709fb3
.PP
Packit 709fb3
In addition, the variant programs
Packit 709fb3
.B egrep
Packit 709fb3
and
Packit 709fb3
.B fgrep
Packit 709fb3
are the same as
Packit 709fb3
.B "grep\ \-E"
Packit 709fb3
and
Packit 709fb3
.BR "grep\ \-F" ,
Packit 709fb3
respectively.
Packit 709fb3
These variants are deprecated, but are provided for backward compatibility.
Packit 709fb3
.
Packit 709fb3
.SH OPTIONS
Packit 709fb3
.SS "Generic Program Information"
Packit 709fb3
.TP
Packit 709fb3
.B \-\^\-help
Packit 709fb3
Output a usage message and exit.
Packit 709fb3
.TP
Packit 709fb3
.BR \-V ", " \-\^\-version
Packit 709fb3
Output the version number of
Packit 709fb3
.B grep
Packit 709fb3
and exit.
Packit 709fb3
.SS "Matcher Selection"
Packit 709fb3
.TP
Packit 709fb3
.BR \-E ", " \-\^\-extended\-regexp
Packit 709fb3
Interpret
Packit 709fb3
.I PATTERN
Packit 709fb3
as an extended regular expression (ERE, see below).
Packit 709fb3
.TP
Packit 709fb3
.BR \-F ", " \-\^\-fixed\-strings
Packit 709fb3
Interpret
Packit 709fb3
.I PATTERN
Packit 709fb3
as a list of fixed strings (instead of regular expressions),
Packit 709fb3
separated by newlines,
Packit 709fb3
any of which is to be matched.
Packit 709fb3
.TP
Packit 709fb3
.BR \-G ", " \-\^\-basic\-regexp
Packit 709fb3
Interpret
Packit 709fb3
.I PATTERN
Packit 709fb3
as a basic regular expression (BRE, see below).
Packit 709fb3
This is the default.
Packit 709fb3
.TP
Packit 709fb3
.BR \-P ", " \-\^\-perl\-regexp
Packit 709fb3
Interpret the pattern as a Perl-compatible regular expression (PCRE).
Packit 709fb3
This is experimental and
Packit 709fb3
.B "grep \-P"
Packit 709fb3
may warn of unimplemented features.
Packit 709fb3
.SS "Matching Control"
Packit 709fb3
.TP
Packit 709fb3
.BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
Packit 709fb3
Use
Packit 709fb3
.I PATTERN
Packit 709fb3
as the pattern.
Packit 709fb3
If this option is used multiple times or is combined with the
Packit 709fb3
.B \-f
Packit 709fb3
.RB ( \-\-file )
Packit 709fb3
option, search for all patterns given.
Packit 709fb3
This option can be used to protect a pattern beginning with \*(lq\-\*(rq.
Packit 709fb3
.TP
Packit 709fb3
.BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
Packit 709fb3
Obtain patterns from
Packit 709fb3
.IR FILE ,
Packit 709fb3
one per line.
Packit 709fb3
If this option is used multiple times or is combined with the
Packit 709fb3
.B \-e
Packit 709fb3
.RB ( \-\-regexp )
Packit 709fb3
option, search for all patterns given.
Packit 709fb3
The empty file contains zero patterns, and therefore matches nothing.
Packit 709fb3
.TP
Packit 709fb3
.BR \-i ", " \-\^\-ignore\-case
Packit 709fb3
Ignore case distinctions, so that characters that differ only in case
Packit 709fb3
match each other.
Packit 709fb3
.TP
Packit 709fb3
.BR \-v ", " \-\^\-invert\-match
Packit 709fb3
Invert the sense of matching, to select non-matching lines.
Packit 709fb3
.TP
Packit 709fb3
.BR \-w ", " \-\^\-word\-regexp
Packit 709fb3
Select only those lines containing matches that form whole words.
Packit 709fb3
The test is that the matching substring must either be at the
Packit 709fb3
beginning of the line, or preceded by a non-word constituent
Packit 709fb3
character.
Packit 709fb3
Similarly, it must be either at the end of the line
Packit 709fb3
or followed by a non-word constituent character.
Packit 709fb3
Word-constituent characters are letters, digits, and the underscore.
Packit 709fb3
This option has no effect if
Packit 709fb3
.B \-x
Packit 709fb3
is also specified.
Packit 709fb3
.TP
Packit 709fb3
.BR \-x ", " \-\^\-line\-regexp
Packit 709fb3
Select only those matches that exactly match the whole line.
Packit 709fb3
For a regular expression pattern, this is like parenthesizing the
Packit 709fb3
pattern and then surrounding it with
Packit 709fb3
.B ^
Packit 709fb3
and
Packit 709fb3
.BR $ .
Packit 709fb3
.TP
Packit 709fb3
.B \-y
Packit 709fb3
Obsolete synonym for
Packit 709fb3
.BR \-i .
Packit 709fb3
.SS "General Output Control"
Packit 709fb3
.TP
Packit 709fb3
.BR \-c ", " \-\^\-count
Packit 709fb3
Suppress normal output; instead print a count of
Packit 709fb3
matching lines for each input file.
Packit 709fb3
With the
Packit 709fb3
.BR \-v ", " \-\^\-invert\-match
Packit 709fb3
option (see below), count non-matching lines.
Packit 709fb3
.TP
Packit 709fb3
.BR \-\^\-color [ =\fIWHEN\fP "], " \-\^\-colour [ =\fIWHEN\fP ]
Packit 709fb3
Surround the matched (non-empty) strings, matching lines, context lines,
Packit 709fb3
file names, line numbers, byte offsets, and separators (for fields and
Packit 709fb3
groups of context lines) with escape sequences to display them in color
Packit 709fb3
on the terminal.
Packit 709fb3
The colors are defined by the environment variable
Packit 709fb3
.BR GREP_COLORS .
Packit 709fb3
The deprecated environment variable
Packit 709fb3
.B GREP_COLOR
Packit 709fb3
is still supported, but its setting does not have priority.
Packit 709fb3
.I WHEN
Packit 709fb3
is
Packit 709fb3
.BR never ", " always ", or " auto .
Packit 709fb3
.TP
Packit 709fb3
.BR \-L ", " \-\^\-files\-without\-match
Packit 709fb3
Suppress normal output; instead print the name
Packit 709fb3
of each input file from which no output would
Packit 709fb3
normally have been printed.
Packit 709fb3
The scanning will stop on the first match.
Packit 709fb3
.TP
Packit 709fb3
.BR \-l ", " \-\^\-files\-with\-matches
Packit 709fb3
Suppress normal output; instead print
Packit 709fb3
the name of each input file from which output
Packit 709fb3
would normally have been printed.
Packit 709fb3
The scanning will stop on the first match.
Packit 709fb3
.TP
Packit 709fb3
.BI \-m " NUM" "\fR,\fP \-\^\-max\-count=" NUM
Packit 709fb3
Stop reading a file after
Packit 709fb3
.I NUM
Packit 709fb3
matching lines.
Packit 709fb3
If the input is standard input from a regular file,
Packit 709fb3
and
Packit 709fb3
.I NUM
Packit 709fb3
matching lines are output,
Packit 709fb3
.B grep
Packit 709fb3
ensures that the standard input is positioned to just after the last
Packit 709fb3
matching line before exiting, regardless of the presence of trailing
Packit 709fb3
context lines.
Packit 709fb3
This enables a calling process to resume a search.
Packit 709fb3
When
Packit 709fb3
.B grep
Packit 709fb3
stops after
Packit 709fb3
.I NUM
Packit 709fb3
matching lines, it outputs any trailing context lines.
Packit 709fb3
When the
Packit 709fb3
.B \-c
Packit 709fb3
or
Packit 709fb3
.B \-\^\-count
Packit 709fb3
option is also used,
Packit 709fb3
.B grep
Packit 709fb3
does not output a count greater than
Packit 709fb3
.IR NUM .
Packit 709fb3
When the
Packit 709fb3
.B \-v
Packit 709fb3
or
Packit 709fb3
.B \-\^\-invert\-match
Packit 709fb3
option is also used,
Packit 709fb3
.B grep
Packit 709fb3
stops after outputting
Packit 709fb3
.I NUM
Packit 709fb3
non-matching lines.
Packit 709fb3
.TP
Packit 709fb3
.BR \-o ", " \-\^\-only\-matching
Packit 709fb3
Print only the matched (non-empty) parts of a matching line,
Packit 709fb3
with each such part on a separate output line.
Packit 709fb3
.TP
Packit 709fb3
.BR \-q ", " \-\^\-quiet ", " \-\^\-silent
Packit 709fb3
Quiet; do not write anything to standard output.
Packit 709fb3
Exit immediately with zero status if any match is found,
Packit 709fb3
even if an error was detected.
Packit 709fb3
Also see the
Packit 709fb3
.B \-s
Packit 709fb3
or
Packit 709fb3
.B \-\^\-no\-messages
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BR \-s ", " \-\^\-no\-messages
Packit 709fb3
Suppress error messages about nonexistent or unreadable files.
Packit 709fb3
.SS "Output Line Prefix Control"
Packit 709fb3
.TP
Packit 709fb3
.BR \-b ", " \-\^\-byte\-offset
Packit 709fb3
Print the 0-based byte offset within the input file
Packit 709fb3
before each line of output.
Packit 709fb3
If
Packit 709fb3
.B \-o
Packit 709fb3
.RB ( \-\^\-only\-matching )
Packit 709fb3
is specified,
Packit 709fb3
print the offset of the matching part itself.
Packit 709fb3
.TP
Packit 709fb3
.BR \-H ", " \-\^\-with\-filename
Packit 709fb3
Print the file name for each match.
Packit 709fb3
This is the default when there is more than one file to search.
Packit 709fb3
.TP
Packit 709fb3
.BR \-h ", " \-\^\-no\-filename
Packit 709fb3
Suppress the prefixing of file names on output.
Packit 709fb3
This is the default when there is only one file
Packit 709fb3
(or only standard input) to search.
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-label= LABEL
Packit 709fb3
Display input actually coming from standard input as input coming from file
Packit 709fb3
.IR LABEL .
Packit 709fb3
This is especially useful when implementing tools like
Packit 709fb3
.BR zgrep ,
Packit 709fb3
e.g.,
Packit 709fb3
.BR "gzip -cd foo.gz | grep --label=foo -H something" .
Packit 709fb3
See also the
Packit 709fb3
.B \-H
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BR \-n ", " \-\^\-line\-number
Packit 709fb3
Prefix each line of output with the 1-based line number
Packit 709fb3
within its input file.
Packit 709fb3
.TP
Packit 709fb3
.BR \-T ", " \-\^\-initial\-tab
Packit 709fb3
Make sure that the first character of actual line content lies on a
Packit 709fb3
tab stop, so that the alignment of tabs looks normal.
Packit 709fb3
This is useful with options that prefix their output to the actual content:
Packit 709fb3
.BR \-H , \-n ,
Packit 709fb3
and
Packit 709fb3
.BR \-b .
Packit 709fb3
In order to improve the probability that lines
Packit 709fb3
from a single file will all start at the same column,
Packit 709fb3
this also causes the line number and byte offset (if present)
Packit 709fb3
to be printed in a minimum size field width.
Packit 709fb3
.TP
Packit 709fb3
.BR \-u ", " \-\^\-unix\-byte\-offsets
Packit 709fb3
Report Unix-style byte offsets.
Packit 709fb3
This switch causes
Packit 709fb3
.B grep
Packit 709fb3
to report byte offsets as if the file were a Unix-style text file,
Packit 709fb3
i.e., with CR characters stripped off.
Packit 709fb3
This will produce results identical to running
Packit 709fb3
.B grep
Packit 709fb3
on a Unix machine.
Packit 709fb3
This option has no effect unless
Packit 709fb3
.B \-b
Packit 709fb3
option is also used;
Packit 709fb3
it has no effect on platforms other than MS-DOS and MS-Windows.
Packit 709fb3
.TP
Packit 709fb3
.BR \-Z ", " \-\^\-null
Packit 709fb3
Output a zero byte (the ASCII
Packit 709fb3
.B NUL
Packit 709fb3
character) instead of the character that normally follows a file name.
Packit 709fb3
For example,
Packit 709fb3
.B "grep \-lZ"
Packit 709fb3
outputs a zero byte after each file name instead of the usual newline.
Packit 709fb3
This option makes the output unambiguous, even in the presence of file
Packit 709fb3
names containing unusual characters like newlines.
Packit 709fb3
This option can be used with commands like
Packit 709fb3
.BR "find \-print0" ,
Packit 709fb3
.BR "perl \-0" ,
Packit 709fb3
.BR "sort \-z" ,
Packit 709fb3
and
Packit 709fb3
.B "xargs \-0"
Packit 709fb3
to process arbitrary file names,
Packit 709fb3
even those that contain newline characters.
Packit 709fb3
.SS "Context Line Control"
Packit 709fb3
.TP
Packit 709fb3
.BI \-A " NUM" "\fR,\fP \-\^\-after\-context=" NUM
Packit 709fb3
Print
Packit 709fb3
.I NUM
Packit 709fb3
lines of trailing context after matching lines.
Packit 709fb3
Places a line containing a group separator
Packit Service cb8816
.RB "(described under " \-\^\-group\-separator )
Packit 709fb3
between contiguous groups of matches.
Packit 709fb3
With the
Packit 709fb3
.B \-o
Packit 709fb3
or
Packit 709fb3
.B \-\^\-only\-matching
Packit 709fb3
option, this has no effect and a warning is given.
Packit 709fb3
.TP
Packit 709fb3
.BI \-B " NUM" "\fR,\fP \-\^\-before\-context=" NUM
Packit 709fb3
Print
Packit 709fb3
.I NUM
Packit 709fb3
lines of leading context before matching lines.
Packit 709fb3
Places a line containing a group separator
Packit Service cb8816
.RB "(described under " \-\^\-group\-separator )
Packit 709fb3
between contiguous groups of matches.
Packit 709fb3
With the
Packit 709fb3
.B \-o
Packit 709fb3
or
Packit 709fb3
.B \-\^\-only\-matching
Packit 709fb3
option, this has no effect and a warning is given.
Packit 709fb3
.TP
Packit 709fb3
.BI \-C " NUM" "\fR,\fP \-" NUM "\fR,\fP \-\^\-context=" NUM
Packit 709fb3
Print
Packit 709fb3
.I NUM
Packit 709fb3
lines of output context.
Packit 709fb3
Places a line containing a group separator
Packit Service cb8816
.RB "(described under " \-\^\-group\-separator )
Packit 709fb3
between contiguous groups of matches.
Packit 709fb3
With the
Packit 709fb3
.B \-o
Packit 709fb3
or
Packit 709fb3
.B \-\^\-only\-matching
Packit 709fb3
option, this has no effect and a warning is given.
Packit Service cb8816
.TP
Packit Service cb8816
.BI \-\^\-group\-separator= SEP
Packit Service cb8816
Use
Packit Service cb8816
.I SEP
Packit Service cb8816
as a group separator. By default
Packit Service cb8816
.I SEP
Packit Service cb8816
is double hyphen
Packit Service cb8816
.RB ( \-\^\- ).
Packit Service cb8816
.TP
Packit Service cb8816
.B \-\^\-no\-group-separator
Packit Service cb8816
Use empty string as a group separator.
Packit 709fb3
.SS "File and Directory Selection"
Packit 709fb3
.TP
Packit 709fb3
.BR \-a ", " \-\^\-text
Packit 709fb3
Process a binary file as if it were text; this is equivalent to the
Packit 709fb3
.B \-\^\-binary\-files=text
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-binary\-files= TYPE
Packit 709fb3
If a file's data or metadata
Packit 709fb3
indicate that the file contains binary data,
Packit 709fb3
assume that the file is of type
Packit 709fb3
.IR TYPE .
Packit 709fb3
Non-text bytes indicate binary data; these are either output bytes that are
Packit 709fb3
improperly encoded for the current locale, or null input bytes when the
Packit 709fb3
.B \-z
Packit 709fb3
option is not given.
Packit 709fb3
.IP
Packit 709fb3
By default,
Packit 709fb3
.I TYPE
Packit 709fb3
is
Packit 709fb3
.BR binary ,
Packit 709fb3
and when
Packit 709fb3
.B grep
Packit 709fb3
discovers that a file is binary it suppresses any further output, and
Packit 709fb3
instead outputs either a one-line message saying that a binary file
Packit 709fb3
matches, or no message if there is no match.
Packit 709fb3
.IP
Packit 709fb3
If
Packit 709fb3
.I TYPE
Packit 709fb3
is
Packit 709fb3
.BR without-match ,
Packit 709fb3
when
Packit 709fb3
.B grep
Packit 709fb3
discovers that a file is binary it assumes that the rest of the file
Packit 709fb3
does not match; this is equivalent to the
Packit 709fb3
.B \-I
Packit 709fb3
option.
Packit 709fb3
.IP
Packit 709fb3
If
Packit 709fb3
.I TYPE
Packit 709fb3
is
Packit 709fb3
.BR text ,
Packit 709fb3
.B grep
Packit 709fb3
processes a binary file as if it were text; this is equivalent to the
Packit 709fb3
.B \-a
Packit 709fb3
option.
Packit 709fb3
.IP
Packit 709fb3
When
Packit 709fb3
.I type
Packit 709fb3
is
Packit 709fb3
.BR binary ,
Packit 709fb3
.B grep
Packit 709fb3
may treat non-text bytes as line terminators even without the
Packit 709fb3
.B \-z
Packit 709fb3
option.  This means choosing
Packit 709fb3
.B binary
Packit 709fb3
versus
Packit 709fb3
.B text
Packit 709fb3
can affect whether a pattern matches a file.  For
Packit 709fb3
example, when
Packit 709fb3
.I type
Packit 709fb3
is
Packit 709fb3
.B binary
Packit 709fb3
the pattern
Packit 709fb3
.B q$ might
Packit 709fb3
match
Packit 709fb3
.B q
Packit 709fb3
immediately followed by a null byte, even though this
Packit 709fb3
is not matched when
Packit 709fb3
.I type
Packit 709fb3
is
Packit 709fb3
.BR text .
Packit 709fb3
Conversely, when
Packit 709fb3
.I type
Packit 709fb3
is
Packit 709fb3
.B binary
Packit 709fb3
the pattern
Packit 709fb3
.B .\&
Packit 709fb3
(period) might not match a null byte.
Packit 709fb3
.IP
Packit 709fb3
.I Warning:
Packit 709fb3
The
Packit 709fb3
.B \-a
Packit 709fb3
option might output binary garbage,
Packit 709fb3
which can have nasty side effects if the output is a terminal and if the
Packit 709fb3
terminal driver interprets some of it as commands.
Packit 709fb3
On the other hand, when reading files whose text encodings are
Packit 709fb3
unknown, it can be helpful to use
Packit 709fb3
.B \-a
Packit 709fb3
or to set
Packit 709fb3
.B LC_ALL='C'
Packit 709fb3
in the environment, in order to find more matches even if the matches
Packit 709fb3
are unsafe for direct display.
Packit 709fb3
.TP
Packit 709fb3
.BI \-D " ACTION" "\fR,\fP \-\^\-devices=" ACTION
Packit 709fb3
If an input file is a device, FIFO or socket, use
Packit 709fb3
.I ACTION
Packit 709fb3
to process it.
Packit 709fb3
By default,
Packit 709fb3
.I ACTION
Packit 709fb3
is
Packit 709fb3
.BR read ,
Packit 709fb3
which means that devices are read just as if they were ordinary files.
Packit 709fb3
If
Packit 709fb3
.I ACTION
Packit 709fb3
is
Packit 709fb3
.BR skip ,
Packit 709fb3
devices are silently skipped.
Packit 709fb3
.TP
Packit 709fb3
.BI \-d " ACTION" "\fR,\fP \-\^\-directories=" ACTION
Packit 709fb3
If an input file is a directory, use
Packit 709fb3
.I ACTION
Packit 709fb3
to process it.
Packit 709fb3
By default,
Packit 709fb3
.I ACTION
Packit 709fb3
is
Packit 709fb3
.BR read ,
Packit 709fb3
i.e., read directories just as if they were ordinary files.
Packit 709fb3
If
Packit 709fb3
.I ACTION
Packit 709fb3
is
Packit 709fb3
.BR skip ,
Packit 709fb3
silently skip directories.
Packit 709fb3
If
Packit 709fb3
.I ACTION
Packit 709fb3
is
Packit 709fb3
.BR recurse ,
Packit 709fb3
read all files under each directory, recursively,
Packit 709fb3
following symbolic links only if they are on the command line.
Packit 709fb3
This is equivalent to the
Packit 709fb3
.B \-r
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-exclude= GLOB
Packit 709fb3
Skip any command-line file with a name suffix that matches the pattern
Packit 709fb3
.IR GLOB ,
Packit 709fb3
using wildcard matching; a name suffix is either the whole
Packit 709fb3
name, or any suffix starting after a
Packit 709fb3
.B /
Packit 709fb3
and before a +non-\fB/\fP.
Packit 709fb3
When searching recursively, skip any subfile whose base name matches
Packit 709fb3
.IR GLOB ;
Packit 709fb3
the base name is the part after the last
Packit 709fb3
.BR / .
Packit 709fb3
A pattern can use
Packit 709fb3
.BR * ,
Packit 709fb3
.BR ? ,
Packit 709fb3
and
Packit 709fb3
.BR [ ... ]
Packit 709fb3
as wildcards, and
Packit 709fb3
.B \e
Packit 709fb3
to quote a wildcard or backslash character literally.
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-exclude-from= FILE
Packit 709fb3
Skip files whose base name matches any of the file-name globs read from
Packit 709fb3
.I FILE
Packit 709fb3
(using wildcard matching as described under
Packit 709fb3
.BR \-\^\-exclude ).
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-exclude-dir= GLOB
Packit 709fb3
Skip any command-line directory with a name suffix that matches the
Packit 709fb3
pattern
Packit 709fb3
.IR GLOB .
Packit 709fb3
When searching recursively, skip any subdirectory
Packit 709fb3
whose base name matches
Packit 709fb3
.IR GLOB .
Packit 709fb3
Ignore any redundant trailing slashes in
Packit 709fb3
.IR GLOB .
Packit 709fb3
.TP
Packit 709fb3
.BR \-I
Packit 709fb3
Process a binary file as if it did not contain matching data; this is
Packit 709fb3
equivalent to the
Packit 709fb3
.B \-\^\-binary\-files=without-match
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BI \-\^\-include= GLOB
Packit 709fb3
Search only files whose base name matches
Packit 709fb3
.I GLOB
Packit 709fb3
(using wildcard matching as described under
Packit 709fb3
.BR \-\^\-exclude ).
Packit 709fb3
.TP
Packit 709fb3
.BR \-r ", " \-\^\-recursive
Packit 709fb3
Read all files under each directory, recursively,
Packit 709fb3
following symbolic links only if they are on the command line.
Packit 709fb3
Note that if no file operand is given, grep searches the working directory.
Packit 709fb3
This is equivalent to the
Packit 709fb3
.B "\-d recurse"
Packit 709fb3
option.
Packit 709fb3
.TP
Packit 709fb3
.BR \-R ", " \-\^\-dereference\-recursive
Packit 709fb3
Read all files under each directory, recursively.
Packit 709fb3
Follow all symbolic links, unlike
Packit 709fb3
.BR \-r .
Packit 709fb3
.SS "Other Options"
Packit 709fb3
.TP
Packit 709fb3
.BR \-\^\-line\-buffered
Packit 709fb3
Use line buffering on output.
Packit 709fb3
This can cause a performance penalty.
Packit 709fb3
.TP
Packit 709fb3
.BR \-U ", " \-\^\-binary
Packit 709fb3
Treat the file(s) as binary.
Packit 709fb3
By default, under MS-DOS and MS-Windows,
Packit 709fb3
.BR grep
Packit 709fb3
guesses whether a file is text or binary as described for the
Packit 709fb3
.B \-\^\-binary\-files
Packit 709fb3
option.
Packit 709fb3
If
Packit 709fb3
.BR grep
Packit 709fb3
decides the file is a text file, it strips the CR characters from the
Packit 709fb3
original file contents (to make regular expressions with
Packit 709fb3
.B ^
Packit 709fb3
and
Packit 709fb3
.B $
Packit 709fb3
work correctly).
Packit 709fb3
Specifying
Packit 709fb3
.B \-U
Packit 709fb3
overrules this guesswork, causing all files to be read and passed to the
Packit 709fb3
matching mechanism verbatim; if the file is a text file with CR/LF
Packit 709fb3
pairs at the end of each line, this will cause some regular
Packit 709fb3
expressions to fail.
Packit 709fb3
This option has no effect on platforms
Packit 709fb3
other than MS-DOS and MS-Windows.
Packit 709fb3
.TP
Packit 709fb3
.BR \-z ", " \-\^\-null\-data
Packit 709fb3
Treat input and output data as sequences of lines, each terminated by
Packit 709fb3
a zero byte (the ASCII NUL character) instead of a newline.
Packit 709fb3
Like the
Packit 709fb3
.B \-Z
Packit 709fb3
or
Packit 709fb3
.B \-\^\-null
Packit 709fb3
option, this option can be used with commands like
Packit 709fb3
.B sort -z
Packit 709fb3
to process arbitrary file names.
Packit 709fb3
.
Packit 709fb3
.SH "REGULAR EXPRESSIONS"
Packit 709fb3
A regular expression is a pattern that describes a set of strings.
Packit 709fb3
Regular expressions are constructed analogously to arithmetic
Packit 709fb3
expressions, by using various operators to combine smaller expressions.
Packit 709fb3
.PP
Packit 709fb3
.B grep
Packit 709fb3
understands three different versions of regular expression syntax:
Packit 709fb3
\*(lqbasic\*(rq (BRE), \*(lqextended\*(rq (ERE) and \*(lqperl\*(rq (PCRE).
Packit 709fb3
In GNU
Packit 709fb3
.B grep
Packit 709fb3
there is no difference in available functionality between basic and
Packit 709fb3
extended syntaxes.
Packit 709fb3
In other implementations, basic regular expressions are less powerful.
Packit 709fb3
The following description applies to extended regular expressions;
Packit 709fb3
differences for basic regular expressions are summarized afterwards.
Packit 709fb3
Perl-compatible regular expressions give additional functionality, and are
Packit 709fb3
documented in pcresyntax(3) and pcrepattern(3), but work only if
Packit 709fb3
PCRE is available in the system.
Packit 709fb3
.PP
Packit 709fb3
The fundamental building blocks are the regular expressions
Packit 709fb3
that match a single character.
Packit 709fb3
Most characters, including all letters and digits,
Packit 709fb3
are regular expressions that match themselves.
Packit 709fb3
Any meta-character with special meaning
Packit 709fb3
may be quoted by preceding it with a backslash.
Packit 709fb3
.PP
Packit 709fb3
The period
Packit 709fb3
.B .\&
Packit 709fb3
matches any single character.
Packit 709fb3
.SS "Character Classes and Bracket Expressions"
Packit 709fb3
A
Packit 709fb3
.I "bracket expression"
Packit 709fb3
is a list of characters enclosed by
Packit 709fb3
.B [
Packit 709fb3
and
Packit 709fb3
.BR ] .
Packit 709fb3
It matches any single
Packit 709fb3
character in that list; if the first character of the list
Packit 709fb3
is the caret
Packit 709fb3
.B ^
Packit 709fb3
then it matches any character
Packit 709fb3
.I not
Packit 709fb3
in the list.
Packit 709fb3
For example, the regular expression
Packit 709fb3
.B [0123456789]
Packit 709fb3
matches any single digit.
Packit 709fb3
.PP
Packit 709fb3
Within a bracket expression, a
Packit 709fb3
.I "range expression"
Packit 709fb3
consists of two characters separated by a hyphen.
Packit 709fb3
It matches any single character that sorts between the two characters,
Packit 709fb3
inclusive, using the locale's collating sequence and character set.
Packit 709fb3
For example, in the default C locale,
Packit 709fb3
.B [a\-d]
Packit 709fb3
is equivalent to
Packit 709fb3
.BR [abcd] .
Packit 709fb3
Many locales sort characters in dictionary order, and in these locales
Packit 709fb3
.B [a\-d]
Packit 709fb3
is typically not equivalent to
Packit 709fb3
.BR [abcd] ;
Packit 709fb3
it might be equivalent to
Packit 709fb3
.BR [aBbCcDd] ,
Packit 709fb3
for example.
Packit 709fb3
To obtain the traditional interpretation of bracket expressions,
Packit 709fb3
you can use the C locale by setting the
Packit 709fb3
.B LC_ALL
Packit 709fb3
environment variable to the value
Packit 709fb3
.BR C .
Packit 709fb3
.PP
Packit 709fb3
Finally, certain named classes of characters are predefined within
Packit 709fb3
bracket expressions, as follows.
Packit 709fb3
Their names are self explanatory, and they are
Packit 709fb3
.BR [:alnum:] ,
Packit 709fb3
.BR [:alpha:] ,
Packit 709fb3
.BR [:cntrl:] ,
Packit 709fb3
.BR [:digit:] ,
Packit 709fb3
.BR [:graph:] ,
Packit 709fb3
.BR [:lower:] ,
Packit 709fb3
.BR [:print:] ,
Packit 709fb3
.BR [:punct:] ,
Packit 709fb3
.BR [:space:] ,
Packit 709fb3
.BR [:upper:] ,
Packit 709fb3
and
Packit 709fb3
.BR [:xdigit:].
Packit 709fb3
For example,
Packit 709fb3
.B [[:alnum:]]
Packit 709fb3
means the character class of numbers and
Packit 709fb3
letters in the current locale.
Packit 709fb3
In the C locale and ASCII
Packit 709fb3
character set encoding, this is the same as
Packit 709fb3
.BR [0\-9A\-Za\-z] .
Packit 709fb3
(Note that the brackets in these class names are part of the symbolic
Packit 709fb3
names, and must be included in addition to the brackets delimiting
Packit 709fb3
the bracket expression.)
Packit 709fb3
Most meta-characters lose their special meaning inside bracket expressions.
Packit 709fb3
To include a literal
Packit 709fb3
.B ]
Packit 709fb3
place it first in the list.
Packit 709fb3
Similarly, to include a literal
Packit 709fb3
.B ^
Packit 709fb3
place it anywhere but first.
Packit 709fb3
Finally, to include a literal
Packit 709fb3
.B \-
Packit 709fb3
place it last.
Packit 709fb3
.SS Anchoring
Packit 709fb3
The caret
Packit 709fb3
.B ^
Packit 709fb3
and the dollar sign
Packit 709fb3
.B $
Packit 709fb3
are meta-characters that respectively match the empty string at the
Packit 709fb3
beginning and end of a line.
Packit 709fb3
.SS "The Backslash Character and Special Expressions"
Packit 709fb3
The symbols
Packit 709fb3
.B \e<
Packit 709fb3
and
Packit 709fb3
.B \e>
Packit 709fb3
respectively match the empty string at the beginning and end of a word.
Packit 709fb3
The symbol
Packit 709fb3
.B \eb
Packit 709fb3
matches the empty string at the edge of a word,
Packit 709fb3
and
Packit 709fb3
.B \eB
Packit 709fb3
matches the empty string provided it's
Packit 709fb3
.I not
Packit 709fb3
at the edge of a word.
Packit 709fb3
The symbol
Packit 709fb3
.B \ew
Packit 709fb3
is a synonym for
Packit 709fb3
.B [_[:alnum:]]
Packit 709fb3
and
Packit 709fb3
.B \eW
Packit 709fb3
is a synonym for
Packit 709fb3
.BR [^_[:alnum:]] .
Packit 709fb3
.SS Repetition
Packit 709fb3
A regular expression may be followed by one of several repetition operators:
Packit 709fb3
.PD 0
Packit 709fb3
.TP
Packit 709fb3
.B ?
Packit 709fb3
The preceding item is optional and matched at most once.
Packit 709fb3
.TP
Packit 709fb3
.B *
Packit 709fb3
The preceding item will be matched zero or more times.
Packit 709fb3
.TP
Packit 709fb3
.B +
Packit 709fb3
The preceding item will be matched one or more times.
Packit 709fb3
.TP
Packit 709fb3
.BI { n }
Packit 709fb3
The preceding item is matched exactly
Packit 709fb3
.I n
Packit 709fb3
times.
Packit 709fb3
.TP
Packit 709fb3
.BI { n ,}
Packit 709fb3
The preceding item is matched
Packit 709fb3
.I n
Packit 709fb3
or more times.
Packit 709fb3
.TP
Packit 709fb3
.BI {, m }
Packit 709fb3
The preceding item is matched at most
Packit 709fb3
.I m
Packit 709fb3
times.
Packit 709fb3
This is a GNU extension.
Packit 709fb3
.TP
Packit 709fb3
.BI { n , m }
Packit 709fb3
The preceding item is matched at least
Packit 709fb3
.I n
Packit 709fb3
times, but not more than
Packit 709fb3
.I m
Packit 709fb3
times.
Packit 709fb3
.PD
Packit 709fb3
.SS Concatenation
Packit 709fb3
Two regular expressions may be concatenated; the resulting
Packit 709fb3
regular expression matches any string formed by concatenating
Packit 709fb3
two substrings that respectively match the concatenated
Packit 709fb3
expressions.
Packit 709fb3
.SS Alternation
Packit 709fb3
Two regular expressions may be joined by the infix operator
Packit 709fb3
.BR | ;
Packit 709fb3
the resulting regular expression matches any string matching
Packit 709fb3
either alternate expression.
Packit 709fb3
.SS Precedence
Packit 709fb3
Repetition takes precedence over concatenation, which in turn
Packit 709fb3
takes precedence over alternation.
Packit 709fb3
A whole expression may be enclosed in parentheses
Packit 709fb3
to override these precedence rules and form a subexpression.
Packit 709fb3
.SS "Back References and Subexpressions"
Packit 709fb3
The back-reference
Packit 709fb3
.BI \e n\c
Packit 709fb3
\&, where
Packit 709fb3
.I n
Packit 709fb3
is a single digit, matches the substring
Packit 709fb3
previously matched by the
Packit 709fb3
.IR n th
Packit 709fb3
parenthesized subexpression of the regular expression.
Packit 709fb3
.SS "Basic vs Extended Regular Expressions"
Packit 709fb3
In basic regular expressions the meta-characters
Packit 709fb3
.BR ? ,
Packit 709fb3
.BR + ,
Packit 709fb3
.BR { ,
Packit 709fb3
.BR | ,
Packit 709fb3
.BR ( ,
Packit 709fb3
and
Packit 709fb3
.BR )
Packit 709fb3
lose their special meaning; instead use the backslashed
Packit 709fb3
versions
Packit 709fb3
.BR \e? ,
Packit 709fb3
.BR \e+ ,
Packit 709fb3
.BR \e{ ,
Packit 709fb3
.BR \e| ,
Packit 709fb3
.BR \e( ,
Packit 709fb3
and
Packit 709fb3
.BR \e) .
Packit 709fb3
.
Packit 709fb3
.SH "ENVIRONMENT VARIABLES"
Packit 709fb3
The behavior of
Packit 709fb3
.B grep
Packit 709fb3
is affected by the following environment variables.
Packit 709fb3
.PP
Packit 709fb3
The locale for category
Packit 709fb3
.BI LC_ foo
Packit 709fb3
is specified by examining the three environment variables
Packit 709fb3
.BR LC_ALL ,
Packit 709fb3
.BR LC_\fIfoo\fP ,
Packit 709fb3
.BR LANG ,
Packit 709fb3
in that order.
Packit 709fb3
The first of these variables that is set specifies the locale.
Packit 709fb3
For example, if
Packit 709fb3
.B LC_ALL
Packit 709fb3
is not set, but
Packit 709fb3
.B LC_MESSAGES
Packit 709fb3
is set to
Packit 709fb3
.BR pt_BR ,
Packit 709fb3
then the Brazilian Portuguese locale is used for the
Packit 709fb3
.B LC_MESSAGES
Packit 709fb3
category.
Packit 709fb3
The C locale is used if none of these environment variables are set,
Packit 709fb3
if the locale catalog is not installed, or if
Packit 709fb3
.B grep
Packit 709fb3
was not compiled with national language support (NLS).
Packit 709fb3
The shell command
Packit 709fb3
.B "locale \-a"
Packit 709fb3
lists locales that are currently available.
Packit 709fb3
.TP
Packit 709fb3
.B GREP_OPTIONS
Packit 709fb3
This variable specifies default options
Packit 709fb3
to be placed in front of any explicit options.
Packit 709fb3
As this causes problems when writing portable scripts,
Packit 709fb3
this feature will be removed in a future release of
Packit 709fb3
.BR grep ,
Packit 709fb3
and
Packit 709fb3
.B grep
Packit 709fb3
warns if it is used.
Packit 709fb3
Please use an alias or script instead.
Packit 709fb3
.TP
Packit 709fb3
.B GREP_COLOR
Packit 709fb3
This variable specifies the color used to highlight matched (non-empty) text.
Packit 709fb3
It is deprecated in favor of
Packit 709fb3
.BR GREP_COLORS ,
Packit 709fb3
but still supported.
Packit 709fb3
The
Packit 709fb3
.BR mt ,
Packit 709fb3
.BR ms ,
Packit 709fb3
and
Packit 709fb3
.B mc
Packit 709fb3
capabilities of
Packit 709fb3
.B GREP_COLORS
Packit 709fb3
have priority over it.
Packit 709fb3
It can only specify the color used to highlight
Packit 709fb3
the matching non-empty text in any matching line
Packit 709fb3
(a selected line when the
Packit 709fb3
.B -v
Packit 709fb3
command-line option is omitted,
Packit 709fb3
or a context line when
Packit 709fb3
.B -v
Packit 709fb3
is specified).
Packit 709fb3
The default is
Packit 709fb3
.BR 01;31 ,
Packit 709fb3
which means a bold red foreground text on the terminal's default background.
Packit 709fb3
.TP
Packit 709fb3
.B GREP_COLORS
Packit 709fb3
Specifies the colors and other attributes
Packit 709fb3
used to highlight various parts of the output.
Packit 709fb3
Its value is a colon-separated list of capabilities
Packit 709fb3
that defaults to
Packit 709fb3
.B ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36
Packit 709fb3
with the
Packit 709fb3
.B rv
Packit 709fb3
and
Packit 709fb3
.B ne
Packit 709fb3
boolean capabilities omitted (i.e., false).
Packit 709fb3
Supported capabilities are as follows.
Packit 709fb3
.RS
Packit 709fb3
.TP
Packit 709fb3
.B sl=
Packit 709fb3
SGR substring for whole selected lines
Packit 709fb3
(i.e.,
Packit 709fb3
matching lines when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is omitted,
Packit 709fb3
or non-matching lines when
Packit 709fb3
.B \-v
Packit 709fb3
is specified).
Packit 709fb3
If however the boolean
Packit 709fb3
.B rv
Packit 709fb3
capability
Packit 709fb3
and the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option are both specified,
Packit 709fb3
it applies to context matching lines instead.
Packit 709fb3
The default is empty (i.e., the terminal's default color pair).
Packit 709fb3
.TP
Packit 709fb3
.B cx=
Packit 709fb3
SGR substring for whole context lines
Packit 709fb3
(i.e.,
Packit 709fb3
non-matching lines when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is omitted,
Packit 709fb3
or matching lines when
Packit 709fb3
.B \-v
Packit 709fb3
is specified).
Packit 709fb3
If however the boolean
Packit 709fb3
.B rv
Packit 709fb3
capability
Packit 709fb3
and the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option are both specified,
Packit 709fb3
it applies to selected non-matching lines instead.
Packit 709fb3
The default is empty (i.e., the terminal's default color pair).
Packit 709fb3
.TP
Packit 709fb3
.B rv
Packit 709fb3
Boolean value that reverses (swaps) the meanings of
Packit 709fb3
the
Packit 709fb3
.B sl=
Packit 709fb3
and
Packit 709fb3
.B cx=
Packit 709fb3
capabilities
Packit 709fb3
when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is specified.
Packit 709fb3
The default is false (i.e., the capability is omitted).
Packit 709fb3
.TP
Packit 709fb3
.B mt=01;31
Packit 709fb3
SGR substring for matching non-empty text in any matching line
Packit 709fb3
(i.e.,
Packit 709fb3
a selected line when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is omitted,
Packit 709fb3
or a context line when
Packit 709fb3
.B \-v
Packit 709fb3
is specified).
Packit 709fb3
Setting this is equivalent to setting both
Packit 709fb3
.B ms=
Packit 709fb3
and
Packit 709fb3
.B mc=
Packit 709fb3
at once to the same value.
Packit 709fb3
The default is a bold red text foreground over the current line background.
Packit 709fb3
.TP
Packit 709fb3
.B ms=01;31
Packit 709fb3
SGR substring for matching non-empty text in a selected line.
Packit 709fb3
(This is only used when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is omitted.)
Packit 709fb3
The effect of the
Packit 709fb3
.B sl=
Packit 709fb3
(or
Packit 709fb3
.B cx=
Packit 709fb3
if
Packit 709fb3
.BR rv )
Packit 709fb3
capability remains active when this kicks in.
Packit 709fb3
The default is a bold red text foreground over the current line background.
Packit 709fb3
.TP
Packit 709fb3
.B mc=01;31
Packit 709fb3
SGR substring for matching non-empty text in a context line.
Packit 709fb3
(This is only used when the
Packit 709fb3
.B \-v
Packit 709fb3
command-line option is specified.)
Packit 709fb3
The effect of the
Packit 709fb3
.B cx=
Packit 709fb3
(or
Packit 709fb3
.B sl=
Packit 709fb3
if
Packit 709fb3
.BR rv )
Packit 709fb3
capability remains active when this kicks in.
Packit 709fb3
The default is a bold red text foreground over the current line background.
Packit 709fb3
.TP
Packit 709fb3
.B fn=35
Packit 709fb3
SGR substring for file names prefixing any content line.
Packit 709fb3
The default is a magenta text foreground over the terminal's default background.
Packit 709fb3
.TP
Packit 709fb3
.B ln=32
Packit 709fb3
SGR substring for line numbers prefixing any content line.
Packit 709fb3
The default is a green text foreground over the terminal's default background.
Packit 709fb3
.TP
Packit 709fb3
.B bn=32
Packit 709fb3
SGR substring for byte offsets prefixing any content line.
Packit 709fb3
The default is a green text foreground over the terminal's default background.
Packit 709fb3
.TP
Packit 709fb3
.B se=36
Packit 709fb3
SGR substring for separators that are inserted
Packit 709fb3
between selected line fields
Packit 709fb3
.RB ( : ),
Packit 709fb3
between context line fields,
Packit 709fb3
.RB ( \- ),
Packit 709fb3
and between groups of adjacent lines when nonzero context is specified
Packit 709fb3
.RB ( \-\^\- ).
Packit 709fb3
The default is a cyan text foreground over the terminal's default background.
Packit 709fb3
.TP
Packit 709fb3
.B ne
Packit 709fb3
Boolean value that prevents clearing to the end of line
Packit 709fb3
using Erase in Line (EL) to Right
Packit 709fb3
.RB ( \\\\\\33[K )
Packit 709fb3
each time a colorized item ends.
Packit 709fb3
This is needed on terminals on which EL is not supported.
Packit 709fb3
It is otherwise useful on terminals
Packit 709fb3
for which the
Packit 709fb3
.B back_color_erase
Packit 709fb3
.RB ( bce )
Packit 709fb3
boolean terminfo capability does not apply,
Packit 709fb3
when the chosen highlight colors do not affect the background,
Packit 709fb3
or when EL is too slow or causes too much flicker.
Packit 709fb3
The default is false (i.e., the capability is omitted).
Packit 709fb3
.PP
Packit 709fb3
Note that boolean capabilities have no
Packit 709fb3
.BR = ...
Packit 709fb3
part.
Packit 709fb3
They are omitted (i.e., false) by default and become true when specified.
Packit 709fb3
.PP
Packit 709fb3
See the Select Graphic Rendition (SGR) section
Packit 709fb3
in the documentation of the text terminal that is used
Packit 709fb3
for permitted values and their meaning as character attributes.
Packit 709fb3
These substring values are integers in decimal representation
Packit 709fb3
and can be concatenated with semicolons.
Packit 709fb3
.B grep
Packit 709fb3
takes care of assembling the result
Packit 709fb3
into a complete SGR sequence
Packit 709fb3
.RB ( \\\\\\33[ ... m ).
Packit 709fb3
Common values to concatenate include
Packit 709fb3
.B 1
Packit 709fb3
for bold,
Packit 709fb3
.B 4
Packit 709fb3
for underline,
Packit 709fb3
.B 5
Packit 709fb3
for blink,
Packit 709fb3
.B 7
Packit 709fb3
for inverse,
Packit 709fb3
.B 39
Packit 709fb3
for default foreground color,
Packit 709fb3
.B 30
Packit 709fb3
to
Packit 709fb3
.B 37
Packit 709fb3
for foreground colors,
Packit 709fb3
.B 90
Packit 709fb3
to
Packit 709fb3
.B 97
Packit 709fb3
for 16-color mode foreground colors,
Packit 709fb3
.B 38;5;0
Packit 709fb3
to
Packit 709fb3
.B 38;5;255
Packit 709fb3
for 88-color and 256-color modes foreground colors,
Packit 709fb3
.B 49
Packit 709fb3
for default background color,
Packit 709fb3
.B 40
Packit 709fb3
to
Packit 709fb3
.B 47
Packit 709fb3
for background colors,
Packit 709fb3
.B 100
Packit 709fb3
to
Packit 709fb3
.B 107
Packit 709fb3
for 16-color mode background colors, and
Packit 709fb3
.B 48;5;0
Packit 709fb3
to
Packit 709fb3
.B 48;5;255
Packit 709fb3
for 88-color and 256-color modes background colors.
Packit 709fb3
.RE
Packit 709fb3
.TP
Packit 709fb3
\fBLC_ALL\fP, \fBLC_COLLATE\fP, \fBLANG\fP
Packit 709fb3
These variables specify the locale for the
Packit 709fb3
.B LC_COLLATE
Packit 709fb3
category,
Packit 709fb3
which determines the collating sequence
Packit 709fb3
used to interpret range expressions like
Packit 709fb3
.BR [a\-z] .
Packit 709fb3
.TP
Packit 709fb3
\fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
Packit 709fb3
These variables specify the locale for the
Packit 709fb3
.B LC_CTYPE
Packit 709fb3
category,
Packit 709fb3
which determines the type of characters,
Packit 709fb3
e.g., which characters are whitespace.
Packit 709fb3
This category also determines the character encoding, that is, whether
Packit 709fb3
text is encoded in UTF-8, ASCII, or some other encoding.  In the C or
Packit 709fb3
POSIX locale, all characters are encoded as a single byte and every
Packit 709fb3
byte is a valid character.
Packit 709fb3
.TP
Packit 709fb3
\fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
Packit 709fb3
These variables specify the locale for the
Packit 709fb3
.B LC_MESSAGES
Packit 709fb3
category,
Packit 709fb3
which determines the language that
Packit 709fb3
.B grep
Packit 709fb3
uses for messages.
Packit 709fb3
The default C locale uses American English messages.
Packit 709fb3
.TP
Packit 709fb3
.B POSIXLY_CORRECT
Packit 709fb3
If set,
Packit 709fb3
.B grep
Packit 709fb3
behaves as POSIX requires; otherwise,
Packit 709fb3
.B grep
Packit 709fb3
behaves more like other GNU programs.
Packit 709fb3
POSIX requires that options that follow file names must be
Packit 709fb3
treated as file names; by default, such options are permuted to the
Packit 709fb3
front of the operand list and are treated as options.
Packit 709fb3
Also, POSIX requires that unrecognized options be diagnosed as
Packit 709fb3
\*(lqillegal\*(rq, but since they are not really against the law the default
Packit 709fb3
is to diagnose them as \*(lqinvalid\*(rq.
Packit 709fb3
.B POSIXLY_CORRECT
Packit 709fb3
also disables \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP,
Packit 709fb3
described below.
Packit 709fb3
.TP
Packit 709fb3
\fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP
Packit 709fb3
(Here
Packit 709fb3
.I N
Packit 709fb3
is
Packit 709fb3
.BR grep 's
Packit 709fb3
numeric process ID.)  If the
Packit 709fb3
.IR i th
Packit 709fb3
character of this environment variable's value is
Packit 709fb3
.BR 1 ,
Packit 709fb3
do not consider the
Packit 709fb3
.IR i th
Packit 709fb3
operand of
Packit 709fb3
.B grep
Packit 709fb3
to be an option, even if it appears to be one.
Packit 709fb3
A shell can put this variable in the environment for each command it runs,
Packit 709fb3
specifying which operands are the results of file name wildcard
Packit 709fb3
expansion and therefore should not be treated as options.
Packit 709fb3
This behavior is available only with the GNU C library, and only
Packit 709fb3
when
Packit 709fb3
.B POSIXLY_CORRECT
Packit 709fb3
is not set.
Packit 709fb3
.
Packit 709fb3
.SH "EXIT STATUS"
Packit 709fb3
Normally the exit status is 0 if a line is selected, 1 if no lines
Packit 709fb3
were selected, and 2 if an error occurred.  However, if the
Packit 709fb3
.B \-q
Packit 709fb3
or
Packit 709fb3
.B \-\^\-quiet
Packit 709fb3
or
Packit 709fb3
.B \-\^\-silent
Packit 709fb3
is used and a line is selected, the exit status is 0 even if an error
Packit 709fb3
occurred.
Packit 709fb3
.
Packit 709fb3
.SH COPYRIGHT
Packit 709fb3
Copyright 1998\(en2000, 2002, 2005\(en2017 Free Software Foundation, Inc.
Packit 709fb3
.PP
Packit 709fb3
This is free software;
Packit 709fb3
see the source for copying conditions.
Packit 709fb3
There is NO warranty;
Packit 709fb3
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit 709fb3
.
Packit 709fb3
.SH BUGS
Packit 709fb3
.SS "Reporting Bugs"
Packit 709fb3
Email bug reports to
Packit 709fb3
.MTO bug-grep@gnu.org "the bug-reporting address" .
Packit 709fb3
An
Packit 709fb3
.URL http://lists.gnu.org/mailman/listinfo/bug-grep "email archive"
Packit 709fb3
and a
Packit 709fb3
.URL http://debbugs.gnu.org/cgi/pkgreport.cgi?package=grep "bug tracker"
Packit 709fb3
are available.
Packit 709fb3
.SS "Known Bugs"
Packit 709fb3
Large repetition counts in the
Packit 709fb3
.BI { n , m }
Packit 709fb3
construct may cause
Packit 709fb3
.B grep
Packit 709fb3
to use lots of memory.
Packit 709fb3
In addition,
Packit 709fb3
certain other obscure regular expressions require exponential time
Packit 709fb3
and space, and may cause
Packit 709fb3
.B grep
Packit 709fb3
to run out of memory.
Packit 709fb3
.PP
Packit 709fb3
Back-references are very slow, and may require exponential time.
Packit 709fb3
.
Packit 709fb3
.SH "SEE ALSO"
Packit 709fb3
.SS "Regular Manual Pages"
Packit 709fb3
awk(1), cmp(1), diff(1), find(1), gzip(1),
Packit 709fb3
perl(1), sed(1), sort(1), xargs(1), zgrep(1),
Packit 709fb3
read(2),
Packit 709fb3
pcre(3), pcresyntax(3), pcrepattern(3),
Packit 709fb3
terminfo(5),
Packit 709fb3
glob(7), regex(7).
Packit 709fb3
.SS "POSIX Programmer's Manual Page"
Packit 709fb3
grep(1p).
Packit 709fb3
.SS "Full Documentation"
Packit 709fb3
A
Packit 709fb3
.URL http://www.gnu.org/software/grep/manual/ "complete manual"
Packit 709fb3
is available.
Packit 709fb3
If the
Packit 709fb3
.B info
Packit 709fb3
and
Packit 709fb3
.B grep
Packit 709fb3
programs are properly installed at your site, the command
Packit 709fb3
.IP
Packit 709fb3
.B info grep
Packit 709fb3
.PP
Packit 709fb3
should give you access to the complete manual.
Packit 709fb3
.
Packit 709fb3
.SH NOTES
Packit 709fb3
This man page is maintained only fitfully;
Packit 709fb3
the full documentation is often more up-to-date.
Packit 709fb3
.\" Work around problems with some troff -man implementations.
Packit 709fb3
.br