如何使用Grep命令根据通配符"LMN2011*"
搜索file name
,该通配符"LMN2011*"
列出了所有以此开头的文件?
我想再判断一下这些文件的内容.
如果file content
有
LMN20113456
我能用GREP
吗?
Grep -ls "LMN2011*" "LMN20113456"
使用shell命令搜索文件名及其内容的正确方法是什么?
如何使用Grep命令根据通配符"LMN2011*"
搜索file name
,该通配符"LMN2011*"
列出了所有以此开头的文件?
我想再判断一下这些文件的内容.
如果file content
有
LMN20113456
我能用GREP
吗?
Grep -ls "LMN2011*" "LMN20113456"
使用shell命令搜索文件名及其内容的正确方法是什么?
Grep不使用"通配符"进行搜索——这就是shell globbing,比如*.jpg.
更多信息和示例:http://www.regular-expressions.info/reference.html
要回答您的问题,您可以找到与grep匹配的文件:
find /somedir -type f -print | grep 'LMN2011' # that will show files whose names contain LMN2011
然后可以搜索其内容(不区分大小写):
find /somedir -type f -print | grep -i 'LMN2011' | xargs grep -i 'LMN20113456'
如果路径可以包含空格,则应使用"零端点"功能:
find /somedir -type f -print0 | grep -iz 'LMN2011' | xargs -0 grep -i 'LMN20113456'