[英]How to find text files not containing text on Linux?
如何在 Linux 上查找不包含某些文本的文件? 基本上我正在寻找以下内容的倒数
find . -print | xargs grep -iL "somestring"
具有讽刺意味的是,您引用的命令完全符合您的描述。 测试一下!
echo "hello" > a
echo "bye" > b
grep -iL BYE a b
只说一个。
我想你可能会混淆 -L 和 -l
find . -print | xargs grep -iL "somestring"
是相反的
find . -print | xargs grep -il "somestring"
顺便考虑一下
find . -print0 | xargs -0 grep -iL "somestring"
甚至
grep -IRiL "somestring" .
您可以单独使用 grep 来完成(无需查找)。
grep -riL "somestring" .
这是grep
使用的参数说明
-L, --files-without-match
each file processed.
-R, -r, --recursive
Recursively search subdirectories listed.
-i, --ignore-case
Perform case insensitive matching.
如果你使用l
小写,你会得到相反的结果(匹配的文件)
-l, --files-with-matches
Only the names of files containing selected lines are written
如果您使用“查找”脚本也在文件夹中执行“grep”:
[root@vps test]# find | xargs grep -Li 1234
grep: .: Is a directory
.
./test.txt
./test2.txt
[root@vps test]#
直接使用“grep”:
# grep -Li 1234 /root/test/*
/root/test/test2.txt
/root/test/test.txt
[root@vps test]#
或在“查找”中指定选项“-type f”...即使您使用查找,您也会投入更多时间(首先是文件列表,然后是 grep)。
通过find和grep查找markdown文件查找不匹配
$ find. -name '* .md' -print0 | xargs -0 grep -iL "title"
直接用grep的-L
搜索只包含markdown文件没有标题的文件
$ grep -iL "title" -r ./* --include '* .md'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.