1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-23 22:22:09 +02:00
tldr/pages.zh/common/grep.md
Sebastiaan Speck f4613659a8
grep: add Dutch translation and fix placeholder highlight (#13030)
* grep: add Dutch translation

* grep: fix placeholder highlighting
2024-06-19 09:46:49 +05:30

36 lines
1.4 KiB
Markdown

# grep
> 使用正则表达式查找文件中的模式。
> 更多信息:<https://www.gnu.org/software/grep/manual/grep.html>.
- 在文件中查找模式:
`grep "{{模式字符串}}" {{路径/到/文件}}`
- 在文件中精确地查找字符串(禁用正则表达式):
`grep {{-F|--fixed-strings}} "{{字符串}}" {{路径/到/文件}}`
- 在指定目录下的所有文件中递归地查找模式,显示匹配的行号并忽略二进制文件:
`grep {{-r|--recursive}} {{-n|--line-number}} --binary-files={{without-match}} "{{模式字符串}}" {{路径/到/目录}}`
- 使用大小写不敏感的扩展正则表达式(支持 `?``+``{}``()``|`):
`grep {{-E|--extended-regexp}} {{-i|--ignore-case}} "{{模式字符串}}" {{路径/到/文件}}`
- 在每个匹配前后、之前或之后打印 3 行上下文:
`grep --{{context|before-context|after-context}} 3 "{{模式字符串}}" {{路径/到/文件}}`
- 以带有颜色的方式,打印每个匹配的文件名和行号:
`grep {{-H|--with-filename}} {{-n|--line-number}} --color=always "{{模式字符串}}" {{路径/到/文件}}`
- 只打印文件中与模式匹配的行:
`grep {{-o|--only-matching}} "{{模式字符串}}" {{路径/到/文件}}`
-`stdin`(标准输入)中查找与模式不匹配的行:
`cat {{路径/到/文件}} | grep {{-v|--invert-match}} "{{模式字符串}}"`