![如何查找不包含给定搜索字符串的文件](https://linux22.com/image/611674/%E5%A6%82%E4%BD%95%E6%9F%A5%E6%89%BE%E4%B8%8D%E5%8C%85%E5%90%AB%E7%BB%99%E5%AE%9A%E6%90%9C%E7%B4%A2%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%96%87%E4%BB%B6.png)
我有一个命令可以查找所有包含字符串“Font”的 PDF 文件
find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -H 'Font' '{}' ';'
我如何更改此命令以使其执行相反的操作?查找所有不包含搜索字符串“Font”的 PDF 文件
答案1
您想使用“-L”选项grep
:
-L, --files-without-match
Only the names of files not containing selected lines are written to standard output. Path-
names are listed once per file searched. If the standard input is searched, the string
``(standard input)'' is written.
答案2
只需添加“L”标志。这起到了相反的作用
find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -HL 'Font' '{}' ';'