我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
我如何在其文件内容中找到包含一个特定的文本序列的所有文件?
下一个不起作用. 它似乎显示系统中的每个单一文件。
find / -type f -exec grep -H 'text-to-find-here' {} \;
当前回答
这个捕捉命令会给你一个准确的结果,当你正在寻找特定的文本在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"
其他回答
试试这个命令,它会给你包含你输入的模式的文件。
sudo grep -inr "your-pattern" /
在这里:i - 忽略案例区别,以便只有在案例中区别的字符相匹配。
n - 确保实际行内容的第一个字符在一张标签站上,以便标签的调整看起来正常。
r - 阅读每个目录下的所有文件,重复,仅按照符号链接,如果它们在命令线上。
试试:
find . -name "*.txt" | xargs grep -i "text_pattern"
使用:
grep -Erni + "text you wanna search"
命令将重复搜索当前目录的所有文件和目录,并打印结果。
注意:如果您的格雷普输出没有颜色,您可以通过在您的壳源文件中使用格雷普=‘格雷普=颜色=总是’的标志来更改它。
我认为值得提到你如何找到:
所有包含至少一个文本的文件,其中包括大量的文本:
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本身,您需要添加一个目录(如上面的示例所示)。
您可以使用 ripgrep 将遵守默认项目的.gitignore 文件。
此分類上一篇
拒绝许可的错误:
rg -i rustacean 2> /dev/null
将默认错误(stderr)输出转向 /dev/null。