我正在寻找foo=目录树中的文本文件中的字符串.它在一台普通的Linux机器上,我有bash shell:
grep -ircl "foo=" *
Run Code Online (Sandbox Code Playgroud)
在目录中还有许多匹配"foo ="的二进制文件.由于这些结果不相关并且减慢了搜索速度,我希望grep跳过搜索这些文件(主要是JPEG和PNG图像).我该怎么办?
我知道有--exclude=PATTERN和--include=PATTERN选项,但模式格式是什么?grep的手册页说:
--include=PATTERN Recurse in directories only searching file matching PATTERN.
--exclude=PATTERN Recurse in directories skip file matching PATTERN.
Run Code Online (Sandbox Code Playgroud)
搜索grep include,grep include exclude,grep exclude和variants没有找到任何相关内容
如果有一种更好的方法只在某些文件中进行grepping,我就是全力以赴; 移动违规文件不是一种选择.我不能只搜索某些目录(目录结构很乱,随处可见).另外,我无法安装任何东西,所以我必须使用常用工具(如grep或建议的查找).
我想排除两者"*log*"并./tags从grep的.
我做的是:
grep -rI "PatternToSearch" ./path --exclude="*log*"
Run Code Online (Sandbox Code Playgroud)
或这个:
grep -rI "PatternToSearch" ./path --exclude="tags"
Run Code Online (Sandbox Code Playgroud)
是否可以在一个grep中合并两个排除模式?
我正在关注如何在Linux上找到包含特定文本的所有文件的最佳答案?在我的项目中搜索字符串.
这是我的命令 grep --include=*.rb -rnw . -e "pattern"
Zsh告诉我 zsh: no matches found: --include=*.rb
似乎grep不支持--include选项.
当我输入时grep --help,它返回
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
Run Code Online (Sandbox Code Playgroud)
不,--include这里
我的grep版本太旧了吗?或者我的命令有问题吗?