在子目录中搜索包含标签 <abbr> 的所有 html 文件

May*_*hux 2 command-line bash

我有一个目录,其中包含许多不同扩展名的文件。我想要的是.html仅列出包含标签的所有文件。

kar*_*rel 5

在终端中,使用该find命令查找所有以 .html 结尾的文件,并使用该grep命令过滤结果以仅显示包含该<abbr>字符串的文件名:

cd /path-to-dir ## change directories to the root directory that you are searching from
find . -name "*.html" -exec grep -l '<abbr>' {} +  
Run Code Online (Sandbox Code Playgroud)

find默认情况下,该命令以递归方式搜索目录层次结构中的文件。

或者将两个命令合并为一个命令:

find /path-to-dir -name "*.html" -exec grep -l '<abbr>' {} +
Run Code Online (Sandbox Code Playgroud)