GREP(1) GREP(1) grep -- , grep [OPTION]... PATTERNS [FILE]... grep [OPTION]... -e PATTERNS ... [FILE]... grep [OPTION]... -f PATTERN_FILE ... [FILE]... grep searches for patterns in each FILE. In the synopsis's first form, which is used if no -e or -f options are present, the first operand PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern. Typically PATTERNS should be quoted when grep is used in a shell command. <<->>, . , , . --help . -V, --version grep . -E, --extended-regexp (EREs -- extended regular expressions, . ). -F, --fixed-strings , . -G, --basic-regexp (BREs -- basic regular expressions, . ). . -P, --perl-regexp , Perl (PCREs -- Perl-compatible regular expressions). , -z (--null-data); grep -P , . -e , --regexp= . -f (--file), . , <<->>. -f , --file= , . -e (--regexp), . , , . -, . -i, --ignore-case , , , . --no-ignore-case . . , -i, , . -v, --invert-match , . -w, --word-regexp , . , , , . , , , . , , , . , -x. -x, --line-regexp , . , -- ^ $. -c, --count ; , . -v, --invert-match (. ) . --color[=], --colour[=] () , , , , , ( ) . GREP_COLORS. never (), always () auto (). -L, --files-without-match ; , , . -l, --files-with-matches ; , , . . -m , --max-count= . , grep , . , -1 ( ), grep . , grep , , , . . grep , . -c --count, grep , . -v --invert-match, grep . -o, --only-matching () , . -q, --quiet, --silent <<>> : . , , . . -s --no-messages. -s, --no-messages , . -b, --byte-offset 0 . -o (--only-matching), . -H, --with-filename . , . GNU. -h, --no-filename . , ( ). --label= Display input actually coming from standard input as input coming from file LABEL. This can be useful for commands that transform a file's contents before searching, e.g., gzip -cd foo.gz | grep --label=foo -H 'some pattern'. See also the -H option. -n, --line-number , 1. -T, --initial-tab , . , : -H,-n -b. , , ( ) . -Z, --null ( NUL ASCII) , . , grep -lZ . , , . , find -print0, perl -0, sort -z xargs -0, , . -A , --after-context= , . (--). -o --only-matching, . -B , --before-context= , . (--). -o --only-matching, . -C , -, --context= . (--). -o --only-matching, . --group-separator= -A, -B -C -- . --no-group-separator -A, -B -C . -a, --text ; --binary-files=text. --binary-files= , , , . , , ; , , , -z . binary, grep , , . - grep , . without-match, grep , ; -I. text, grep ; -a. binary, grep -z. , binary text . , binary, q$ q, , , text. , binary, . () . Warning: The -a option might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands. On the other hand, when reading files whose text encodings are unknown, it can be helpful to use -a or to set LC_ALL='C' in the environment, in order to find more matches even if the matches are unsafe for direct display. -D , --devices= , FIFO , . read, , , . skip, - . -d , --directories= , . read, , . skip, - . recurse, , , . -r. --exclude=_ , _ (wildcard); , , , (/) . , _; , . *, ? [...] , \ . --exclude-from= , - ( , --exclude). --exclude-dir=_ , _. , _. , _. -I , ; --binary-files=without-match. --include=_ , _ ( , --exclude). --include --exclude, . --include, --exclude, , --include . -r, --recursive , , . , grep . -d recurse. -R, --dereference-recursive . -r . --line-buffered . . -U, --binary . MS-DOS MS-Windows grep , , , --binary-files. grep , , ( ^ $). -U , ; CR/LF ( ) , . , MS-DOS MS-Windows. -z, --null-data , ( NUL ASCII), . -Z --null, sort -z, . -- , . . grep : <> (, BRE), <> (, ERE) <> (PCRE). GNU grep -- . , , . ; . Perl- pcre2syntax(3) pcre2pattern(3), , PCRE. , . , , , . , , , . . . , , . , [ ]. . ^, , ; , , . , [0123456789] . Within a bracket expression, a range expression consists of two characters separated by a hyphen. In the default C locale, it matches any single character that appears between the two characters in ASCII order, inclusive. For example, [a-d] is equivalent to [abcd]. In other locales the behavior is unspecified: [a-d] might be equivalent to [abcd] or [aBbCcDd] or some other bracket expression, or it might fail to match any character, or the set of characters that it matches might be erratic, or it might be invalid. To obtain the traditional interpretation of bracket expressions, you can use the C locale by setting the LC_ALL environment variable to the value C. , , : [:alnum:] (-), [:alpha:] (), [:blank:] ( ), [:cntrl:] (), [:digit:] (), [:graph:] (), [:lower:] ( ), [:print:] (), [:punct:] (), [:space:] (), [:upper:] ( ) [:xdigit:] (). , [[:alnum:]] , . C ASCII [0-9A-Za-z]. , , . . ], . , ^, . , -, . ^ $ , . \< \> . \b , \B , . \w [_[:alnum:]], \W -- [^_[:alnum:]]. : ? . * . + . {n} n . {n,} n . {,m} m . GNU. {n,m} n , m . ; , , . |; , . , , , . , . \n, n -- , , n- , . ?, +, {, |, ( ) ; \?, \+, \{, \|, \( \). 0, ; 1, ; 2, . , -q, --quiet --silent 0, . grep . LC_foo LC_ALL, LC_foo, LANG . , , . , LC_ALL , LC_MESSAGES pt_BR, LC_MESSAGES , . , grep (NLS), C. locale -a . GREP_COLORS --color. , ; ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36, rv ne (.. <<>>). . sl= SGR ( , , -v, , -v ). , rv -v, SGR . (.. , ). cx= SGR ( , , -v, , -v ). , rv -v, SGR . (.. , ). rv , sl= cx= , -v. <<>> (.. ). mt=01;31 SGR ( , , -v, , -v ). ms= mc= . . ms=01;31 SGR ( , -v ). sl= ( cx= rv) , . . mc=01;31 SGR ( , -v). cx= ( sl= rv) , . . fn=35 SGR , . , . ln=32 SGR , . , . bn=32 SGR , . , . se=36 SGR , (:), (-) , (--). , . ne , Erase in Line (EL) to Right (\33[K) , . , EL. , terminfo back_color_erase (bce), , , EL . <<>> (.. ). , =... . (.. <<>>) , <<>>. Select Graphic Rendition (SGR) , , . SGR . grep SGR (\33[...m). , , 1 , 4 , 5 , 7 , 39 , 30 37 , 90 97 16- , 38;5;0 38;5;255 88- 256- , 49 , 40 47 , 100 107 16- , 48;5;0 48;5;255 88- 256- . LC_ALL, LC_COLLATE, LANG LC_COLLATE, , [a-z]. LC_ALL, LC_CTYPE, LANG LC_CTYPE, , , . , UTF-8, ASCII - . C POSIX . LC_ALL, LC_MESSAGES, LANG LC_MESSAGES, , grep . C . POSIXLY_CORRECT , grep POSIX; grep GNU. POSIX , , , ; . , POSIX , <<>> (illegal), , <<>> (invalid). ; . Copyright 1998-2000, 2002, 2005-2025 Free Software Foundation, Inc. ; . - , . . . {n,m} grep . , , grep. . The following example outputs the location and contents of any line containing "f" and ending in ".c", within all files in the current directory whose names contain "g" and end in ".h". The -n option outputs line numbers, the -- argument treats expansions of "*g*.h" starting with "-" as file names not options, and the empty file /dev/null causes file names to be output even if only one file name happens to be of the form "*g*.h". $ grep -n -- 'f.*\.c$' *g*.h /dev/null argmatch.h:1:/* definitions and prototypes for argmatch.c , , 1 argmatch.h. , , , , . awk(1), cmp(1), diff(1), find(1), perl(1), sed(1), sort(1), xargs(1), read(2), pcre2(3), pcre2syntax(3), pcre2pattern(3), terminfo(5), glob(7), regex(7) . info grep , info grep . () Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. GNU grep 3.12-modified 2025-03-21 GREP(1)