如何递归查找包含特定单词的 .doc 文件?

Tom*_*Tom 11 linux bash grep cat

我在 Ubuntu 下使用 bash。

目前这适用于当前目录:

catdoc *.doc | grep "specificword" 
Run Code Online (Sandbox Code Playgroud)

但是我有很多带有 .doc 文件的子目录。

我怎样才能递归地搜索“特定词”?

use*_*686 14

使用find递归搜索:

find -name '*.doc' -exec catdoc {} + | grep "specificword"
Run Code Online (Sandbox Code Playgroud)

这也将输出文件名:

find -name '*.doc' | while read -r file; do
    catdoc "$file" | grep -H --label="$file" "specificword"
done
Run Code Online (Sandbox Code Playgroud)

(通常我会使用find ... -print0 | while read -rd "" file,但可能有 0.0001% 的可能性是必要的,所以我不再关心了。)


Rob*_*kob 5

您可能想查看recoll,它是支持多种不同文档格式的 Linux 和 Unix 系统的全文搜索工具。但是,它是基于索引的,即它必须在实际搜索之前为您要搜索的文档编制索引。(感谢 pabouk 指出这一点)。

还有一个 GUI 和一个命令行。

有关更多信息,请参阅文档