如何在具有特定文本字符串和扩展名的文件夹中查找所有文件?

ale*_*lex 5 terminal grep macos

我正在使用 OS X。

我需要在具有.php扩展名和41文件内容中某处的字符串的目录中查找文件。

我尝试使用grep.

grep -R 41 *.php
Run Code Online (Sandbox Code Playgroud)

然而,这似乎只能在 CWD 中找到文件,而不是在子目录中。

我也试过弄乱find.

我无法弄清楚这一点。

我究竟做错了什么?

Ign*_*ams 10

你需要两者。

find . -name '*.php' -type f -exec grep -q 41 {} \; -print
Run Code Online (Sandbox Code Playgroud)