如何在每次匹配之前在文件名中获取 grep 颜色?

chi*_*cal 6 unix grep colors

如果我grep -ir "somethingtomatch" .从当前目录运行,我通常会得到如下结果:

./some/path/file1.html: filecontent filecontent keyword filecontent
./some/path/file2.html: filecontent filecontent filecontent keyword
./some/path/file3.html: filecontent keyword filecontent filecontent
./some/path/file4.html: keyword filecontent filecontent filecontent
Run Code Online (Sandbox Code Playgroud)

我使用过,grep --color=auto -ir 'somethingtomatch" .但它只在红色突出显示上以白色突出显示关键字。我也在尝试获取左侧颜色编码的文件名。我怎么做?

我在 OS X 中使用 Terminal.app 和 bash 和 xterm(我也尝试过 xterm-color)。

p.v*_*zli 7

您可以使用 $GREP_COLORS 环境变量更改颜色。在您的情况下,您可以尝试export GREP_COLORS='fn=1;32'将文件名的颜色更改为绿色。