欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入免费知识星球。

Linux常用命令-30:grep

常用命令 迷途小书童 2年前 (2022-06-07) 638次浏览 0个评论

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

语法格式: grep [参数]

常用参数:

linux grep

示例

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

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

linux grep

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

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

# 结合其它命令使用
history | grep man

linux grep

# 在当前目录下递归搜索包含字符串text的文件,结果中显示出现的行数
grep "text" . -r -n

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

您必须 登录 才能发表评论!

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

请关闭 Adblock 等类似浏览器插件,然后刷新页面访问,感谢您的支持!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.