4

Linux常用命令-30:grep

 1 year ago
source link: https://xugaoxiang.com/2022/06/07/linux-cmds-30-grep/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

grep 的意思是全面搜索正则表达式,是强大的文本搜索工具,用于过滤和搜索特定字符,也是使用最为广泛的命令了。

语法格式: grep [参数]

常用参数:

244e22cfffb1b399.png
# 在文件中搜索字符串
grep "putText" motion_detector.py

# 在多个文件中搜索
grep "putText" test1.py test2.py test3.py

2a947d6b40723af3.png

# 输出除了字符串外的其它内容
grep -v "putText" test.py

# 统计字符串出现的行数总数
grep -c "putText" test.py

# 结合其它命令使用
history | grep man
2bc4462eef464a82.png
# 在当前目录下递归搜索包含字符串text的文件,结果中显示出现的行数
grep "text" . -r -n

# 使用正则表达式进行搜索
grep -P "[a-z]+\." motion_detector.py

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK