-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep.cheat
95 lines (64 loc) · 2.04 KB
/
grep.cheat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
% grep
;
; Common
;
# [common] recursive, line-number, suppress error messages, skip binary file
grep -rnsI
# [common] multi patterns match - 同时搜索多个模式字符串
grep -e <PATTERN_1> -e <PATTERN_2>
;
; Regexp Selection
;
# [option][select] fix string - 纯字符串匹配
grep -F <STRING>
# [option][select] extended regular expressions - 扩展正则
grep -E <PATTERNS>
# [option][select] basic regular expressions - 基础正则, 默认模式
grep -G <PATTERNS>
# [option][select][file] take PATTERNS from <FILE> - 从文件获取模式字符串
grep -f <FILE>
;
; Miscellaneous
;
# [option][select] recursive - 递归, 不解析软链接文件, 默认应用 -H
grep -r
# [option][select] recursive, and follow all symlinks - 递归, 解析软链接文件, 默认应用 -H
grep -R
# [option][select] ignore case - 忽略大小写
grep -i
# [option][select] match whole word - 匹配整个单词
grep -w
# [option][select] match whole line - 匹配整行
grep -x
# [option][select] non-matching lines - 没有匹配的行
grep -v
# [option][select] skip binary file - 跳过二进制文件
grep -I
;
; File Path
;
# [option][file] search only files that match GLOB - 指定目录内搜索
grep --include=<GLOB>
# [option][file] skip files that match GLOB - 跳过指定文件
grep --exclude=<GLOB>
# [option][file] skip files that match any file pattern from <FILE> - 以文件形式提供跳过的文件
grep --exclude-from=<FILE>
# [option][file] skip directories that match GLOB - 跳过指定目录
grep --exclude-dir=GLOB
;
; Output
;
# [option][output] show each parts of lines that match
grep -o
# [option][output] suppress the file name prefix - 不打印文件名
grep -h
# [option][output] max select NUM lines
grep -m<NUM>
# [option][output] print NUM lines of before context
grep -B<NUM>
# [option][output] print NUM lines of after context
grep -A<NUM>
# [option][output] print NUM lines of central context
grep -C<NUM>
# [option][output] print only name of files which matches line - 只打印匹配内容的文件名
grep -l