Linux common commands-30: grep

grep means comprehensive search for regular expressions. It is a powerful text search tool for filtering and searching for specific characters, and it is also the most widely used command.

Syntax format: grep [parameter]

Common parameters:

Example

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

 # 输出除了字符串外的其它内容grep -v "putText" test.py # 统计字符串出现的行数总数grep -c "putText" test.py # 结合其它命令使用history | grep man

 # 在当前目录下递归搜索包含字符串text的文件,结果中显示出现的行数grep "text" . -r -n # 使用正则表达式进行搜索grep -P "[az]+\." motion_detector.py

This article is reprinted from https://xugaoxiang.com/2022/06/07/linux-cmds-30-grep/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment