"grep" 可搜索各 "FILE" 中的 "PATTERN" 及標準輸齣。

默認情況下,"PATTERN" 是 BRE "基本正則錶達式 (basic regular expression)"。

譬如:grep -i 'hello world' menu.h main.c


grep [OPTION]... PATTERN [FILE]...

# 參數 EN 解釋 中文翻譯 備注
01 -E, --extended-regexp PATTERN is an extended regular expression (ERE)
02 -F, --fixed-strings PATTERN is a set of newline-separated fixed strings
03 -G, --basic-regexp PATTERN is a basic regular expression (BRE)
04 -P, --perl-regexp PATTERN is a Perl regular expression
05 -e, --regexp=PATTERN use PATTERN for matching
06 -f, --file=FILE obtain PATTERN from FILE
07 -i, --ignore-case ignore case distinctions
08 -w, --word-regexp force PATTERN to match only whole words
09 -x, --line-regexp force PATTERN to match only whole lines
10 -z, --null-data a data line ends in 0 byte, not newline
Miscellaneous 雜項
# 參數 EN 解釋 中文翻譯 備注
01 -s, --no-messages suppress error messages
02 -v, --invert-match select non-matching lines
03 -V, --version print version information and exit
04 --help display this help and exit 顯示幫助並退齣
05 --mmap deprecated no-op; evokes a warning
Output control 輸齣控製
# 參數 EN 解釋 中文翻譯 備注
01 -m, --max-count=NUM stop after NUM matches
02 -b, --byte-offset print the byte offset with output lines
03 -n, --line-number print line number with output lines
04 --line-buffered flush output on every line
05 -H, --with-filename print the file name for each match
06 -h, --no-filename suppress the file name prefix on output
07 --label=LABEL use LABEL as the standard input file name prefix
08 -o, --only-matching show only the part of a line matching PATTERN
09 -q, --quiet, --silent suppress all normal output
10 --binary-files=TYPE assume that binary files are TYPE; TYPE is 'binary', 'text', or 'without-match'
11 -a, --text equivalent to --binary-files=text
12 -I equivalent to --binary-files=without-match
13 -d, --directories=ACTION how to handle directories; ACTION is 'read', 'recurse', or 'skip'
14 -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is 'read' or 'skip'
15 -r, --recursive like --directories=recurse
16 -R, --dereference-recursive likewise, but follow all symlinks
17 --include=FILE_PATTERN search only files that match FILE_PATTERN
18 --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN
19 --exclude-from=FILE skip files matching any file pattern from FILE
20 --exclude-dir=PATTERN directories that match PATTERN will be skipped.
21 -L, --files-without-match print only names of FILEs containing no match
22 -l, --files-with-matches print only names of FILEs containing matches
23 -c, --count print only a count of matching lines per FILE
24 -T, --initial-tab make tabs line up (if needed)
25 -Z, --null print 0 byte after FILE name
Context control 上下文控製
# 參數 EN 解釋 中文翻譯 備注
01 -B, --before-context=NUM print NUM lines of leading context
02 -A, --after-context=NUM print NUM lines of trailing context
03 -C, --context=NUM print NUM lines of output context
04 -NUM same as --context=NUM
05 --color[=WHEN], --colour[=WHEN] use markers to highlight the matching strings; WHEN is 'always', 'never', or 'auto'
06 -U, --binary do not strip CR characters at EOL (MSDOS/Windows)
07 -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS/Windows)


功能 # 命令規範 文字解釋 示例 示例解釋