我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
我认为值得提到你如何找到:
所有包含至少一个文本的文件,其中包括大量的文本:
grep -rlf ../patternsFile.txt .
出口:
./file1
./file2
./file4
上述,由每个文本组成:
cat ../patternsFile.txt | xargs -I{} sh -c "echo {}; grep -rl \"{}\" ."
出口:
pattern1
./file1
./file2
pattern2
./file1
./file4
pattern3
./file1
./file2
./file4
请注意,为了不匹配模式File.txt本身,您需要添加一个目录(如上面的示例所示)。
其他回答
试试:
find / -type f -exec grep -H 'text-to-find-here' {} \;
将搜索所有文件系统,因为 / 是根文件夹。
Home 文件夹使用:
find ~/ -type f -exec grep -H 'text-to-find-here' {} \;
目前使用文件夹:
find ./ -type f -exec grep -H 'text-to-find-here' {} \;
您可以使用 ripgrep 将遵守默认项目的.gitignore 文件。
此分類上一篇
拒绝许可的错误:
rg -i rustacean 2> /dev/null
将默认错误(stderr)输出转向 /dev/null。
这个捕捉命令会给你一个准确的结果,当你正在寻找特定的文本在Linux -
grep -inRsH “文本要被搜索” /path/to/dir(它可以是“。
i stands for ignore case distinctions R stands for recursive and it also includes symlinks. It is better to use 'R' instead of 'r' n stands for "it will print line number." s stands for "suppress error messages" H stands for "it will print the file name for each match"
grep -insr "pattern" *
i: 在 PATTERN 和输入文件中忽略案例区别. n: 在输入文件中预定每个输出线的 1 行号. s: 删除关于不存在或不可读的文件的错误消息. r: 阅读每个目录下的所有文件,重复。
试试这:
find . | xargs grep 'word' -sl