grep

GREP(1)                     General Commands Manual                    GREP(1)



NAME
       grep, egrep, fgrep - æå°å¹éç»å®æ¨¡å¼çè¡

æ»è§ SYNOPSIS
       grep [options] PATTERN [FILE...]
       grep [options] [-e PATTERN | -f FILE] [FILE...]

æè¿° DESCRIPTION
       Grep æ索以 FILE å½åçæ件è¾å¥
       (æèæ¯æ åè¾å¥ï¼å¦æ没ææå®æ件åï¼æèç»åºçæ件åæ¯ -
       çè¯)ï¼å¯»æ¾å«æä¸ç»å®çæ¨¡å¼ PATTERN ç¸å¹éçå容çè¡ã é»è®¤æåµä¸ï¼ grep
       å°æå«æå¹éå容çè¡æå°åºæ¥ã

       å¦å¤ï¼ä¹å¯ä»¥ä½¿ç¨ä¸¤ä¸ªåç§ç¨åº egrep å fgrep ã Egrep ä¸ grep -E ç¸åã
       Fgrep ä¸ grep -F ç¸åã

é项 OPTIONS
       -A NUM, --after-context=NUM
              æå°åºç´§éå¹éçè¡ä¹åçä¸æ NUM è¡ãå¨ç¸é»çå¹éç»ä¹é´å°ä¼æå°åå®¹æ¯ --
              çä¸è¡ã

       -a, --text
              å°ä¸ä¸ªäºè¿å¶æ件è§ä¸ºä¸ä¸ªææ¬æ件æ¥å¤çï¼å®ä¸ --binary-
              files=text é项çä»·ã

       -B NUM, --before-context=NUM
              æå°åºå¹éçè¡ä¹åçä¸æ NUM è¡ãå¨ç¸é»çå¹éç»ä¹é´å°ä¼æå°åå®¹æ¯ --
              çä¸è¡ã

       -C NUM, --context=NUM
              æå°åºå¹éçè¡çä¸ä¸æååå NUM è¡ãå¨ç¸é»çå¹éç»ä¹é´å°ä¼æå°åå®¹æ¯ --
              çä¸è¡ã

       -b, --byte-offset
              å¨è¾åºçæ¯è¡åé¢åæ¶æå°åºå½åè¡å¨è¾å¥æ件ä¸çåèå移éã

       --binary-files=TYPE
              å¦æä¸ä¸ªæ件çèµ·å§å 个åè表ææ件åå«äºè¿å¶æ°æ®ï¼é£ä¹åå®æ件æ¯
              TYPE ç±»åçãé»è®¤æåµä¸ï¼ TYPE æ¯ binary ï¼å¹¶ä¸ grep
              ä¸è¬ä¼è¾åºä¸ä¸ªä¸è¡çæ¶æ¯è¯´ä¸ä¸ªäºè¿å¶æ件å¹éï¼æèå¦æ没æå¹éçè¯å°±æ²¡ææ¶æ¯è¾åºãå¦æç±»å
              TYPE æ¯ without-match ï¼é£ä¹ grep åå®äºè¿å¶æ件ä¸ä¼å¹éï¼è¿æ ·åä¸
              -I é项çä»·ãå¦æç±»å TYPE æ¯ text ï¼é£ä¹ grep
              å°ä¸ä¸ªäºè¿å¶æ件è§ä¸ºææ¬æ件æ¥å¤çï¼å®ä¸ -a é项çä»·ã è¦åï¼ grep
              --binary-files=text
              å¯è½ä¼è¾åºäºè¿å¶çæ ç¨å容ãå¦æè¾åºè®¾å¤æ¯ä¸ä¸ªç»ç«¯ï¼å¹¶ä¸ç»ç«¯ç驱å¨å°è¿äºè¾åºä¸‐
              çä¸äºå½ä½å½ä»¤ï¼å¯è½ä¼å¸¦æ¥æ¶å£çå¯ä½ç¨ã

       --colour[=WHEN], --color[=WHEN]
              å¨å¹éçè¡å¨å´ä»¥ GREP_COLOR ç¯å¢åéä¸æå®çè®°å·æ¥æ è®°ãWHEN å¯ä»¥æ¯
              `never', `always', ææ¯ `auto'ã

       -c, --count
              ç¦æ‐
              ¢é常çè¾åºï¼ä½ä¸ºæ¿ä»£ï¼ä¸ºæ¯ä¸ä¸ªè¾å¥æ件æå°ä¸ä¸ªå¹éçè¡çæ»æ°ãå¦æ使ç¨
              -v, --invert-match é项 (åè§ä¸é¢)ï¼å°æ¯ä¸å¹éçè¡çæ»æ°ã

       -D ACTION, --devices=ACTION
              å¦æè¾å¥æ件æ¯ä¸ä¸ªè®¾å¤ï¼FIFO ææ¯å¥æ¥å (socket) ï¼ä½¿ç¨å¨ä½
              ACTION æ¥å¤çå®ãé»è®¤æåµä¸ï¼å¨ä½ ACTION æ¯ read
              ï¼æå³ç设å¤å°è§ä¸ºæ®éæ件é£æ ·æ¥è¯»ãå¦æå¨ä½ ACTION æ¯ skip
              ï¼å°ä¸å¤çèç´æ¥è·³è¿è®¾å¤ã

       -d ACTION, --directories=ACTION
              å¦æè¾å¥æ件æ¯ä¸ä¸ªç®å½ï¼ä½¿ç¨å¨ä½ ACTION
              æ¥å¤çå®ãé»è®¤æåµä¸ï¼å¨ä½ ACTION æ¯ read
              ï¼æå³çç®å½å°è§ä¸ºæ®éæ件é£æ ·æ¥è¯»ãå¦æå¨ä½ ACTION æ¯ skip
              ï¼å°ä¸å¤çèç´æ¥è·³è¿ç®å½ãå¦æå¨ä½ ACTION æ¯ recurse ï¼ grep
              å°éå½å°è¯»æ¯ä¸ç®å½ä¸çæææ件ãè¿æ ·åå -r é项çä»·ã

       -E, --extended-regexp
              å°æ¨¡å¼ PATTERN ä½ä¸ºä¸ä¸ªæ©å±çæ£å表达å¼æ¥è§£é (åè§ä¸é¢)ã

       -e PATTERN, --regexp=PATTERN
              使ç¨æ¨¡å¼ PATTERN ä½ä¸ºæ¨¡å¼ï¼å¨ä¿æ¤ä»¥ - 为起å§ç模å¼æ¶æç¨ã

       -F, --fixed-strings
              å°æ¨¡å¼ PATTERN è§ä¸ºä¸ä¸ªåºå®çå符串çå表ï¼ç¨æ°è¡ (newlines)
              åéï¼åªè¦å¹éå¶ä¸ä¹ä¸å³å¯ã

       -P, --perl-regexp
              å°æ¨¡å¼ PATTERN ä½ä¸ºä¸ä¸ª Perl æ£å表达å¼æ¥è§£éã

       -f FILE, --file=FILE
              ä»æ件 FILE ä¸è·å模å¼ï¼æ¯è¡ä¸ä¸ªã空æ件å«æ0个模å¼ï¼å æ‐
              ¤ä¸å¹éä»»ä½ä¸è¥¿ã

       -G, --basic-regexp
              å°æ¨¡å¼ PATTERN ä½ä¸ºä¸ä¸ªåºæ¬çæ£åè¡¨è¾¾å¼ (åè§ä¸é¢)
              æ¥è§£éãè¿æ¯é»è®¤å¼ã

       -H, --with-filename
              为æ¯ä¸ªå¹éæå°æ件åã

       -h, --no-filename
              å½æç´¢å¤ä¸ªæ件æ¶ï¼ç¦æ¢å¨è¾åºçåé¢å ä¸æ件ååç¼ã

       --help è¾åºä¸ä¸ªç®çç帮å©ä¿¡æ¯ã

       -I     å¤çä¸ä¸ªäºè¿å¶æ件ï¼ä½æ¯è®¤ä¸ºå®ä¸åå«å¹éçå容ãè¿å --binary-
              files=without-match é项çä»·ã

       -i, --ignore-case
              忽ç¥æ¨¡å¼ PATTERN åè¾å¥æ件ä¸ç大å°åçåå«ã

       -L, --files-without-match
              ç¦æ‐
              ¢é常çè¾åºï¼ä½ä¸ºæ¿ä»£ï¼æå°åºæ¯ä¸ªå¨é常æåµä¸ä¸ä¼äº§çè¾åºçè¾å¥æ件çåå‐
              ã对æ¯ä¸ªæ件çæ«æå¨éå°ç¬¬ä¸ä¸ªå¹éçæ¶åå°±ä¼åæ¢ã

       -l, --files-with-matches
              ç¦æ‐
              ¢é常çè¾åºï¼ä½ä¸ºæ¿ä»£ï¼æå°åºæ¯ä¸ªå¨é常æåµä¸ä¼äº§çè¾åºçè¾å¥æ件çåå‐
              ã对æ¯ä¸ªæ件çæ«æå¨éå°ç¬¬ä¸ä¸ªå¹éçæ¶åå°±ä¼åæ¢ã

       -m NUM, --max-count=NUM
              å¨æ¾å° NUM
              个å¹éçè¡ä¹åï¼ä¸å读è¿ä¸ªæ件ãå¦æè¾å¥æ¯æ¥èªä¸ä¸ªæ®éæ件çæ åè¾å¥ï¼å¹¶ä¸å·²ç»è¾åºäº
              NUM 个å¹éçè¡ï¼ grep
              ä¿è¯æ åè¾å¥è¢«å®ä½äºéåºæ¶çæåä¸æ¬¡å¹éçè¡ä¹åï¼ä¸ç®¡æ¯å¦æå®äºè¦è¾åºç´§éçä¸æçè¡ãè¿æ ·å¯ä»¥ä½¿ä¸ä¸ªè°ç¨ç¨åºæ¢å¤æç´¢ãå½
              grep å¨ NUM 个å¹éçè¡ä¹ååæ¢ï¼å®ä¼è¾åºä»»ä½ç´§éçä¸æçè¡ãå½ä½¿ç¨äº
              -c æ --count é项çæ¶åï¼ grep ä¸ä¼è¾åºæ¯ NUM æ´å¤çè¡ãå½æå®äº -v æ
              --invert-match é项çæ¶åï¼ grep ä¼å¨è¾åº NUM 个ä¸å¹éçè¡ä¹ååæ¢ã

       --mmap å¦æå¯è½çè¯ï¼ä½¿ç¨ mmap(2) ç³»ç»è°ç¨æ¥è¯»åè¾å¥ï¼èä¸æ¯é»è®¤ç
              read(2) ç³»ç»è°ç¨ãå¨ä¸äºæåµä¸ï¼ --mmap
              æä¾è¾å¥½çæ§è½ãä½æ¯ï¼å¦æä¸ä¸ªè¾å¥æä»¶å¨ grep æ‐
              £å¨æä½æ¶å¤§å°åçååï¼æèå¦æåçäºä¸ä¸ª I/O éè¯¯ï¼ --mmap
              å¯è½å¯¼è´ä¸å¯ç¥çè¡ä¸º (åæ¬core dumps)ã

       -n, --line-number
              å¨è¾åºçæ¯è¡åé¢å ä¸å®æå¨çæ件ä¸å®çè¡å·ã

       -o, --only-matching
              åªæ¾ç¤ºå¹éçè¡ä¸ä¸ PATTERN ç¸å¹éçé¨åã

       --label=LABEL
              å°å®éä¸æ¥èªæ åè¾å¥çè¾å¥è§ä¸ºæ¥èªè¾å¥æ件 LABEL ãè¿å¯¹äº zgrep
              è¿æ ·çå·¥å·é常æç¨ï¼ä¾å¦ï¼ gzip -cd foo.gz |grep --label=foo
              something

       --line-buffering
              使ç¨è¡ç¼å²ï¼it can be a performance penality.

       -q, --quiet, --silent
              å®éãä¸åæ åè¾åºåä»»ä½ä¸è¥¿ãå¦ææ¾å°ä»»ä½å¹éçå容就ç«å³ä»¥ç¶æå¼ 0
              éåºï¼å³ä½¿æ£æµå°äºé误ã åè§ -s æ --no-messages é项ã

       -R, -r, --recursive
              éå½å°è¯»æ¯ä¸ç®å½ä¸çæææ件ãè¿æ ·åå -d recurse é项çä»·ã

         --include=PATTERN
              ä»ä»å¨æç´¢å¹é PATTERN çæ件æ¶å¨ç®å½ä¸éå½æç´¢ã

         --exclude=PATTERN
              å¨ç®å½ä¸éå½æç´¢ï¼ä½æ¯è·³è¿å¹é PATTERN çæ件ã

       -s, --no-messages
              ç¦æ¢è¾åºå³äºæ件ä¸åå¨æä¸å¯è¯»çé误信æ¯ã
              对äºå¯ç§»æ¤æ§éè¦æ³¨æï¼ä¸ GNU grep ä¸åï¼ä¼ ç»ç grep ä¸éµå®
              POSIX.2 è§èï¼å ä¸ºä¼ ç»ç grep 缺å°ä¸ä¸ª -q é项ï¼èå®ç -s é项ä¸
              GNU grep ç -q é项è¡ä¸ºç¸ä¼¼ãéè¦å¯ç§»æ¤å°ä¼ ç» grep ç shell
              èæ¬åºå½é¿åä½¿ç¨ -q å -s é项ï¼èåºå½å°è¾åºéå®åå° /dev/null ã

       -U, --binary
              å°æ件è§ä¸ºäºè¿å¶ãé»è®¤æåµä¸ï¼å¨ MS-DOS å MS-Windows ç³»ç»ä¸ï¼
              grep éè¿ä»æ件ä¸è¯»å头é¨ç 32kB å容æ¥å¤æå®çæ件类åãå¦æ grep
              å¤ææ件æ¯ä¸ä¸ªææ¬æ件ï¼å®å°åå§æ件å容ä¸ç CR å符å»é¤ (使å¾å«æ
              ^ å $ çæ£å表达å¼å¯ä»¥æ£å¸¸å·¥ä½)ãæå® -U
              å°ä¸è¿è¡è¿äºå·¥ä½ï¼è使æææ件ä¿æä¸åå°è¯»åå¹¶ä¼ éç»å¹éæºå¶ãå¦ææ件æ¯ä¸ä¸ªä»¥
              CR/LF æ¢è¡çææ¬æ件ï¼è¿æ ·ä½å°å¯¼è´ä¸äºæ‐
              £å表达å¼å¤±è´¥ãè¿ä¸ªéé¡¹å¨ MS-DOS å MS-Windows ä¹å¤çç³»ç»ä¸‐
              æ æã

       -u, --unix-byte-offsets
              æ¥å Unix é£æ ¼çåèå移éãè¿ä¸ªå¼å³ä½¿å¾ grep æ¥åå‐
              èå移éæ¶ï¼å°æ件ä½ä¸º Unix é£æ ¼çææ¬æ件çå¾ï¼ä¹å°±æ¯è¯´å° CR å‐
              符å»æãè¿å°äº§çä¸å¨ä¸å° Unix 主æºä¸è¿è¡ grep
              å®å¨ç¸åçç»æãé¤éåæ¶ä½¿ç¨ -b é项ï¼å¦åè¿ä¸ªé项æ æãè¿ä¸ªéé¡¹å¨ MS-
              DOS å MS-Windows ä¹å¤çç³»ç»ä¸æ æã

       -V, --version
              åæ åé误è¾åºæå° grep ççæ¬å·ãçæ¬å·åºå½åå«å¨ææç bug æ¥åä¸
              (åè§ä¸é¢)ã

       -v, --invert-match
              æ¹åå¹éçæä¹ï¼åªéæ©ä¸å¹éçè¡ã

       -w, --word-regexp
              åªéæ©å«æè½ç»æå®æ´çè¯çå¹éçè¡ãå¤ææ¹æ³æ¯å¹éçåå‐
              符串å¿é¡»æ¯ä¸è¡çå¼å§ï¼æèæ¯å¨ä¸ä¸ªä¸å¯è½æ¯è¯çç»æçå符ä¹åãä¸æ‐
              ¤ç¸ä¼¼ï¼å®å¿é¡»æ¯ä¸è¡çç»æï¼æèæ¯å¨ä¸ä¸ªä¸å¯è½æ¯è¯çç»æçå‐
              符ä¹åãè¯çç»æå符æ¯åæ¯ï¼æ°åï¼è¿æä¸å线ã

       -x, --line-regexp
              åªéæ©è½å¹éå®æ´ä¸è¡çå¹éã

       -y     -i çåä¹è¯ï¼åºå¼ä¸ç¨ã

       -Z, --null
              è¾åºä¸ä¸ªå¨é¶åè (ASCII ç ä¸ç NUL å符)
              èä¸æ¯ä¸è¬æåµä¸è¾åºå¨æ件åä¹åçå符ãä¾å¦ï¼ grep -lZ
              å¨æ¯ä¸ªæ件åä¹åè¾åºä¸ä¸ªå¨é¶å‐
              èèä¸æ¯æ®éçæ°è¡ç¬¦ãè¿ä¸ªé项使å¾è¾åºæ¸æ¥æç½ï¼å³ä½¿æ件åç表示ä¸‐
              åå«ç¹æ®å符æ¯å¦æ°è¡ç¬¦ãè¿ä¸ªé项å¯ä»¥ä¸å½ä»¤ find -print0, perl
              -0, sort -z, å xargs -0
              ä¸èµ·ä½¿ç¨ï¼æ¥å¤çä»»æçæ件åï¼å³ä½¿æ¯é£äºå«ææ°è¡ç¬¦çæ件åã

æ£åè¡¨è¾¾å¼ REGULAR EXPRESSIONS
       ä¸ä¸ªæ£å表达å¼æ¯ä¸ä¸ªæè¿°äºä¸ä¸ªå符串éåç模å¼ãæ‐
       £å表达å¼çæé 类似äºç®æ¯è¡¨è¾¾å¼ï¼ä½¿ç¨åç§åæ ·çæä½ç¬¦æ¥å°æ´å°ç表达å¼è¿å¨ä¸èµ·ã

       Grep è½ç解两ç§ä¸åçæ¬çæ£å表达å¼è¯æ³ï¼“basic” å “extended”ãå¨
       GNU grep ä¸ï¼ä¸¤ç§è¯æ³å¯ä»¥å®ç°çåè½æ¯æ²¡æåºå«çãå¨å¶ä»å®ç°ä¸ï¼åºæ¬
       (basic) æ£å表达å¼è¡¨è¾¾è½åè¦å¼±ä¸ç¹ãä¸é¢çæè¿°éç¨äºæ©å±ç (extended) æ‐
       £å表达å¼ï¼å®ä¸åºæ¬æ£å表达å¼çåºå«ä¼å¨æååä¸ä¸ªæ»ç»ã

       åºæ¬çæé åæ¯å¹éå个å符çæ£å表达å¼ã大é¨åå符ï¼åæ¬ææåæ¯åæ°å‐
       ï¼æ¯å¹éå®ä»¬èªèº«çæ£å表达å¼ãä»»ä½å·æç¹æ®å«ä¹çåå‐
       符å¯ä»¥éè¿åç½®ä¸ä¸ªåææ æ¥å¼ç¨ã(may be quoted by preceding it with a
       backslash.)

       æ¹æ¬å·è¡¨è¾¾å¼ (bracket) æ¯ä¸ä¸ªå符åºåï¼æ¾å¨ [ å ] å½ä¸ãå®å¹éåºåä¸‐
       çä»»ä½ä¸ä¸ªå符ï¼å¦æåºåä¸ç第ä¸ä¸ªå符æ¯è±å符 (caret) ^ é£ä¹å®å¹é ä¸å¨
       åºåä¸çä»»ä½ä¸ä¸ªå符ãä¾å¦ï¼æ£åè¡¨è¾¾å¼ [0123456789] å¹éä»»ä½ä¸ä¸ªæ°åã

       å¨æ¹æ¬å·è¡¨è¾¾å¼ä¹ä¸ï¼ä¸ä¸ª èå´è¡¨è¾¾å¼ (range) ç±ä¸¤ä¸ªå符ç»æï¼ä¸‐
       é´ç¨ä¸ä¸ªè¿å符 (hyphen) åéãå®å¹éå¨è¿ä¸¤ä¸ªå符ä¹é´çä»»ä½ä¸ä¸ªå‐
       符ï¼ä½¿ç¨æ¬å°åçåºå顺åºåå符éã(that sorts between the two
       characters,inclusive, using the locale's collating sequence and
       character set.) ä¾å¦ï¼å¨é»è®¤ç C localeä¸ï¼ [a-d] ä¸ [abcd] ç‐
       ä»·ãå¸åçï¼è®¸å¤ locale å°å符以åå¸é¡ºåºæåºï¼å¨è¿äº locale ä¸ï¼ [a-d]
       ä¸ä¸ [abcd] çä»·ï¼ä¾å¦å®å¯è½ä¸ [aBbCcDd] ç‐
       ä»·ãè¦è·å¾ä¼ ç»ç对æ¹æ¬å·è¡¨è¾¾å¼ç解éï¼å¯ä»¥è®¾å®ç¯å¢åé LC_ALL å¼ä¸º C
       æ¥ä½¿ç¨ locale C ã

       æåï¼å¨æ¹æ¬å·è¡¨è¾¾å¼ä¸æä¸äºé¢å®ä¹çå符类ï¼å¦ä¸æ示ãå®ä»¬çåå‐
       æ¯èªè¯´æçï¼å®ä»¬æ¯ [:alnum:](åæ¯åæ°å), [:alpha:](åæ¯), [:cntrl:](),
       [:digit:](æ°å), [:graph:](), [:lower:](å°ååæ¯), [:print:](å¯æå°å符),
       [:punct:](), [:space:](ç©ºæ ¼), [:upper:](大ååæ¯), å [:xdigit:]
       ãä¾å¦ï¼ [[:alnum:]] æææ¯ [0-9A-Za-z] ï¼ä½æ¯åä¸ç§è¡¨ç¤ºæ¹æ³ä¾èµäº locale
       C åASCII å符ç¼ç ï¼èåä¸ç§æ¯ä¸ locale åå符éæ å³çã(注æè¿äºå符类åä¸‐
       çæ¹æ¬å·ä¹æ¯ç¬¦å·å称çä¸é¨åï¼å¿é¡»åå«å¨ç¨æ¥ä¸ºåºåå®ççæ¹æ¬å·ä¹ä¸ã)

       大å¤æ°åå符å¤äºåºåä¸æ¶ä¼å¤±å»å®ä»¬çç¹æ®æä¹ã为äºåå«ä¸ä¸ªåé¢æä¹
       (literal) ç ] ï¼éè¦å°å®æ¾å¨åºåçæåãä¸æ¤ç¸ä¼¼ï¼ä¸ºäºåå«ä¸ä¸ªåé¢æä¹
       (literal) ç ^ ï¼éè¦å°å®æ¾å¨é¤äºåºåæåä¹å¤çå¶ä»ä½ç½®ãæåï¼ä¸ºäºåå«ä¸ä¸ªå‐
       é¢æä¹ (literal) ç - ï¼éè¦å°å®æ¾å¨åºåæåã

       å¥ç¹ç¬¦ (period) .  å¹éä»»ä½ä¸ä¸ªå符ãç¬¦å· \w æ¯ [[:alnum:]] çåä¹è¯ï¼
       \W æ¯ [^[:alnum]] çåä¹è¯ã

       è±å符 (caret) ^ åç¾åæ è®° (dollar) $ åå«æ¯å¹éä¸è¡çé¦é¨åå°¾é¨ç空å‐
       串çåå符ãç¬¦å· \< å \> åå«æ¯å¹éä¸ä¸ªè¯çé¦é¨åå°¾é¨ç空å串çåå符ã符å·
       \b å¹éä¸ä¸ªè¯è¾¹ç¼ (edge) ç空å串ï¼ç¬¦å· \B å¹é ä¸
       å¤äºä¸ä¸ªè¯çè¾¹ç¼ç空å串ã

       ä¸ä¸ªæ£å表达å¼åé¢å¯ä»¥è·éå¤ç§éå¤æä½ç¬¦ä¹ä¸ã
       ?      ååç项æ¯å¯éçï¼æå¤å¹éä¸æ¬¡ã
       *      ååç项å¯ä»¥å¹éé¶æ¬¡æå¤æ¬¡ã
       +      ååç项å¯ä»¥å¹éä¸æ¬¡æå¤æ¬¡ã
       {n}    ååç项å°å¹éæ°å¥½ n 次ã
       {n,}   ååç项å¯ä»¥å¹é n ææ´å¤æ¬¡ã
       {n,m}  ååç项å°å¹éè³å° n è¯ï¼ä½æ¯ä¸ä¼è¶è¿ m 次ã

       两个æ£å表达å¼å¯ä»¥è¿æ¥å°ä¸èµ·ï¼å¾åºçæ‐
       £å表达å¼å¯ä»¥å¹éä»»ä½ç±ä¸¤ä¸ªåå«å¹éè¿æ¥åçå表达å¼çåå符串è¿æ¥èæçå‐
       符串ã

       两个æ£å表达å¼å¯ä»¥ç¨ä¸ç¼æä½ç¬¦ | èåå°ä¸èµ·ï¼å¾åºçæ‐
       £å表达å¼å¯ä»¥å¹éä»»ä½å¹éèååçä»»ä½ä¸ä¸ªå表达å¼çå符串ã

       éå¤æä½ç¬¦çä¼å级æ¯è¿æ¥é«ï¼æ¥ä¸æ¥åæ¯éæ©çä¼å级é«ãä¸ä¸ªå®æ´çå‐
       表达å¼å¯ä»¥ç¨åæ¬å· (parentheses) æ¬ä½æ¥è¶è¶è¿äºä¼å级è§åã(to override
       these precedence rules.)

       ååå¼ç¨ \n ä¸ï¼ n æ¯ä¸ä¸ªæ°åï¼å¹éæ£å表达å¼ä¸ï¼ä»¥ç¬¬ n 个åæ¬å·æ¬ä½çå‐
       表达å¼å·²å¹éçåå符串ã

       å¨åºæ¬æ£å表达å¼ä¸ï¼åå符 ?, +, {, |, (, å )
       丧失äºå®ä»¬çç¹æ®æä¹ï¼ä½ä¸ºæ¿ä»£ï¼ä½¿ç¨å åææ ç (backslash) çæ¬ \?, \+,
       \{, \|, \(, å \) ã

       ä¼ ç»ç egrep ä¸æ¯æåå符 { ï¼å¹¶ä¸ä¸äº egrep çå®ç°éè¿æ¯æ \{
       æ¥ä»£æ¿å®ï¼å æ¤å¯ç§»æ¤çèæ¬åºå½é¿å å¨ egrep ä¸ä½¿ç¨ { 模å¼ï¼åºå½ä½¿ç¨
       [{] æ¥å¹éä¸ä¸ªåé¢æä¹ (literal) ç { ã

       GNU egrep éè¿å设å¦æ { å¤äº an invalid interval specification
       çèµ·å§ï¼å°±ä¸æ¯ä¸ä¸ªç¹æ®å符ï¼æ¥æ¯æä¼ ç»çç¨æ³ãä¾å¦ï¼shell å½ä»¤ egrep
       '{1' å°ä¼æç´¢è¿ä¸ªä¸¤å符çå符串 {1 èä¸æ¯æ¥åå¨æ£å表达å¼ä¸åçäºè¯‐
       æ³é误ãPOSIX.2
       å许è¿ä¸ªè¡ä¸ºï¼å°å¶è§ä¸ºä¸ä¸ªæ©å±ï¼ä½æ¯å¯ç§»æ¤çèæ¬åºå½é¿å使ç¨å®ã

ç¯å¢åé ENVIRONMENT VARIABLES
       Grep çè¡ä¸ºåä¸åç¯å¢åéå½±åã

       ä¸ä¸ª locale LC_foo æ¯éè¿æä¸é¢ç顺åºï¼ LC_ALL, LC_foo, LANG,
       æ£æ¥è¿ä¸ä¸ªç¯å¢åéçåå¼èç¡®å®çã设置äºç第ä¸ä¸ªåéæå®äº localeãä¾å¦ï¼å¦æ
       LC_ALL 没æ设置ï¼ä½æ¯ LC_MESSAGES 设置为 pt_BR ï¼é£ä¹å·´è¥¿çè¡èçè¯
       (Brazilian Portuguese) å°ç¨ä½ LC_MESSAGES locale
       çå¼ãå¦æ没æ设置è¿å¶ä¸ä»»ä½ä¸ä¸ªç¯å¢åéï¼æè没æå®è£æ设置ç locale
       ç®å½ï¼æèå¦æ grep 没æå°å½å®¶åè¯è¨æ¯æ (national language support (NLS))
       ç¼è¯å¨åï¼å°é»è®¤ä½¿ç¨ locale Cã

       GREP_OPTIONS
              è¿ä¸ªåéæå®äºå°æ¾å¨æææ¾å¼æå®çé项ä¹åçé»è®¤é项ãä¾å¦ï¼å¦æ
              GREP_OPTIONS æ¯ '--binary-files=without-match
              --directories=skip' çè¯ï¼ grep
              å°åå·²ç»å¨ä»»ä½æ¾å¼æå®çé项ä¹åæå®äº --binary-files=without-match
              å --directories=skip é项é£æ ·æ¥è¿ä½ãéé¡¹ä»¥ç©ºç½ (whitespace)
              åéãä¸ä¸ªåææ  (backslash) 使å¾ä¸ä¸ä¸ªåç¬¦è½¬ä¹ (escape)ï¼å æ‐
              ¤å¯ä»¥ç¨æ¥æå®ä¸ä¸ªå«æ空ç½æèåææ çé项ã

       GREP_COLOR
              æå®ç¨æ¥é«äº®æ¾ç¤ºçæ è®°ã

       LC_ALL, LC_COLLATE, LANG
              è¿äºåéæå®äº locale LC_COLLATE ï¼å³å®äºè§£é类似 [a-z]
              çèå´è¡¨è¾¾å¼æ¶çåºåé¡ºåº (collating sequence) ã

       LC_ALL, LC_CTYPE, LANG
              è¿äºé项æå®äº locale LC_CTYPE ï¼å³å®äºå符çç±»åï¼ä¾å¦ï¼åªäºå‐
              符æ¯ç©ºç½ (whitespace) ã

       LC_ALL, LC_MESSAGES, LANG
              è¿äºé项æå®äº locale LC_MESSAGES ï¼å³å®äº grep çæ¶æ¯ä½¿ç¨çè¯‐
              è¨ãé»è®¤ç locale C 使ç¨ç¾å½è±è¯çæ¶æ¯ã

       POSIXLY_CORRECT
              å¦æ设置äºçè¯ï¼ grep å°å POSIX.2 è¦æ±çé£æ ·æ¥è¿ä½ï¼å¦åï¼ grep
              å°åå¶ä» GNU ç¨åºä¸æ ·æ¥è¿ä½ãPOSIX.2
              è¦æ±æ件åä¹åçé项å¿é¡»è§ä¸ºæ件åï¼é»è®¤æåµä¸ï¼è¿äºé项被交æ¢å°æä½æ°å表çåé¢ï¼è¢«å½ä½é项æ¥å¤çãåæ¶ï¼
              POSIX.2 è¦æ±ä¸å¯è¯å«çé项å¨è¯ææ¶æ¯ä¸è¡¨ç¤ºä¸º
              “illegal”ï¼ä½æ¯æ¢ç¶å®ä»¬æ²¡æçæ£è§¦ç¯æ³å¾ï¼å æ‐
              ¤é»è®¤æåµä¸å®ä»¬å¨è¯æ (diagnose) æ¶æ¯ä¸è¡¨ç¤ºä¸º “invalid”ã
              POSIXLY_CORRECT åæ¶ç¦æ¢äºä¸é¢æè¿°ç _N_GNU_nonoption_argv_flags_ã

       _N_GNU_nonoption_argv_flags_
              (è¿é N æ¯ grep's æ°åå½¢å¼çè¿ç¨IDã) å¦æè¿ä¸ªç¯å¢åéçå¼ç第 i 个å‐
              ç¬¦æ¯ 1 ï¼é£ä¹ä¸å° grep ç第 i
              个æä½æ°è§ä¸ºä¸ä¸ªé项ï¼å³ä½¿å®çä¸å»åãshell
              å¯ä»¥å°è¿ä¸ªåé设置å¨å®è¿è¡çæ¯ä¸ªå½ä»¤çç¯å¢ä¸‐
              ï¼æå®åªä¸ªæä½æ°æ¯æ件åéé符æ©å±çç»æï¼å æ‐
              ¤ä¸åºå½è¢«è§ä¸ºé项ãè¿ä¸ªè¡ä¸ºåªæå¨ä½¿ç¨ GNU C
              åºæ¶ææï¼å¹¶ä¸åªæå¨ POSIXLY_CORRECT 没æ设置çæ¶åã

è¯æ DIAGNOSTICS
       ä¸è¬å°ï¼å¦ææ¾å°äºéæ©çè¡ï¼éåºæ¶ç¶æå¼ä¸º0ï¼å¦å为1ãä½æ¯å¦æåçé误ï¼éåºæ¶ç¶æå¼æ¯2ï¼é¤éæå®äº
       -q æ --quiet æ --silent é项ï¼å¹¶ä¸æ¾å°äºéæ©çè¡ã

BUGS
       bug æ¥åççµåé®ä»¶å°åæ¯ bug-gnu-utils@gnu.orgã ä¸å®è¦å¨“Subject:”ä¸å¸¦æ
       “grep” è¿ä¸ªè¯ã

       å¨ {n,m} ç»æä¸éå¤æ¬¡æ°è¿å¤ä¼å¯¼è´ grep 使ç¨å¤§éåå‐
       ãå¦å¤ï¼ä¸äºè¿åæ¦æ¶©çæ£å表达å¼éè¦ææ°çº§çæ¶é´å空é´ï¼å¯è½ä¼å¯¼è´ grep
       èå°½ææååã

       ååå¼ç¨ (backreferences) é常æ¢ï¼å¯è½éè¦ææ°çº§çæ¶é´ã

[ä¸æçç»´æ¤äºº]
       è¢ä¹é§ <bbbush@163.com>

[ä¸æçææ°æ´æ°]
       2003.11.03

ãä¸å½linux论åmanæå页翻è¯è®¡åã:
       http://cmpp.linuxforum.net

è·
       æ¬é¡µé¢ä¸æçç±ä¸æ man æå页计åæä¾ã
       ä¸æ man æå页计åï¼https://github.com/man-pages-zh/manpages-zh



                                  GNU Project                          GREP(1)