我如何将find和grep的结果输出为filename => found

时间:2018-07-25 00:09:15

标签: linux bash shell grep

如何合并格式为find的命令grepfilename: => string的结果?

例如find . -maxdepth 2 -type f -name .env -exec grep 'CURRENT_ENV' {} \;,当发现CURRENT_ENV字符串时,该命令将向我显示该行,例如CURRENT_ENV=staging。我想按以下方式修改输出:./site1.com: CURRENT_ENV=staging

我不明白如何实现。可能吗?

1 个答案:

答案 0 :(得分:4)

  -H, --with-filename
          Print the file name for each match.  This is the default when
          there is more than one file to search.

http://man7.org/linux/man-pages/man1/grep.1.html