相关疑难解决方法(0)

使用grep --exclude/ - include语法不要浏览某些文件

我正在寻找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或建议的查找).

unix shell search command-line grep

757
推荐指数
12
解决办法
61万
查看次数

如何使用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 shell grep command

8
推荐指数
1
解决办法
1万
查看次数

grep --include命令在OSX Zsh中不起作用

我正在关注如何在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版本太旧了吗?或者我的命令有问题吗?

macos grep zsh

5
推荐指数
1
解决办法
2498
查看次数

标签 统计

grep ×3

shell ×2

command ×1

command-line ×1

linux ×1

macos ×1

search ×1

unix ×1

zsh ×1