关于 find 和 grep 的问题

use*_*609 2 linux command-line grep find

关于以下find命令行

find . -type f -exec grep -l strings {} \;
Run Code Online (Sandbox Code Playgroud)

我不明白-exec and的用法{} \

Hai*_* Vu 6

对于找到的每个查找(或目录),执行以下命令:

grep -l strings {} \;
Run Code Online (Sandbox Code Playgroud)

{} 是占位符,代表找到的文件/目录。这 \; 在语法上是必需的。

  • `\;` 终止 `-exec` 的参数(它告诉 `find` 停止解析属于你要运行的命令的参数)。您几乎可以使用 `";"` 或 `';'` 代替 - 关键是,如果不转义分号,shell 本身就会将其视为命令分隔符。 (3认同)