如何在目录/子目录中搜索PDF文件的内容?我在找一些命令行工具。grep似乎不能搜索PDF文件。


当前回答

我的实际版本的pdfgrep(1.3.0)允许以下:

pdfgrep -HiR 'pattern' /path

当执行pdfgrep——help时:

H:打印每个匹配项的文件名。 i:忽略大小写区别。 R:递归搜索目录。

它在我的Ubuntu上运行得很好。

其他回答

试着在一个简单的脚本中使用'acroread',就像上面那样

使用pdfgrep:

pdfgrep -HinR 'FWCOSP' DatenModel/

在这个命令中,我在DatenModel/文件夹中搜索单词FWCOSP。

正如你在输出中看到的,你可以有文件名和行号:

我使用的选项是:

-i : Ignores, case for matching
-H : print the file name for each match
-n : prefix each match with the number of the page where it is found
-R : same as -r, but it also follows all symlinks.

我的实际版本的pdfgrep(1.3.0)允许以下:

pdfgrep -HiR 'pattern' /path

当执行pdfgrep——help时:

H:打印每个匹配项的文件名。 i:忽略大小写区别。 R:递归搜索目录。

它在我的Ubuntu上运行得很好。

我喜欢@sjr的答案,但我更喜欢xargs vs -exec。我发现xargs更通用。例如,使用-P,我们可以在必要时利用多个cpu。

find . -name '*.pdf' | xargs -P 5 -I % pdftotext % - | grep --with-filename --label="{}" --color "pattern"

Recoll是一个很棒的Unix/Linux全文GUI搜索应用程序,支持几十种不同的格式,包括PDF。它甚至可以将查询的确切页码和搜索词传递给文档查看器,从而允许您直接从它的GUI跳转到结果。

Recoll还提供了一个可行的命令行界面和一个web浏览器界面。