首页 > 解决方案 > 如何将 find 和 grep 的结果输出为 filename => found

问题描述

如何结合命令的结果findgrep格式:filename: => string

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

我不明白我怎么能做到这一点。可能吗?

标签: linuxbashshellgrep

解决方案


  -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


推荐阅读