我如何在其文件内容中找到包含一个特定的文本序列的所有文件?

下一个不起作用. 它似乎显示系统中的每个单一文件。

find / -type f -exec grep -H 'text-to-find-here' {} \;

当前回答

grep -lrnw '/root/Desktop/ipozal' -e 'geolocation'

例如:

我的文件夹名称是“Ipozal”它放在“/root/Desktop”我想在所有文件中找到此文本“地理位置”

其他回答

试试这个命令,它会给你包含你输入的模式的文件。

sudo grep -inr "your-pattern" /

在这里:i - 忽略案例区别,以便只有在案例中区别的字符相匹配。

n - 确保实际行内容的第一个字符在一张标签站上,以便标签的调整看起来正常。

r - 阅读每个目录下的所有文件,重复,仅按照符号链接,如果它们在命令线上。

A Simple find can work handy. alias it in your ~/.bashrc 文件:

alias ffind find / -type f | xargs grep

开始一个新的终端和问题:

ffind 'text-to-find-here'

试试:

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' {} \;

这个捕捉命令会给你一个准确的结果,当你正在寻找特定的文本在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"

find /path -type f -exec grep -l "string" {} \;

评论的解释

查找是一个命令,允许您在特定路径的子目录中找到文件和其他对象,如目录和链接,如果您不指定该文件名称应满足的面具,则列出所有目录对象。

-type f specifies that it should proceed only files, not directories etc.
-exec grep specifies that for every found file, it should run grep command, passing its filename as an argument to it, by replacing {} with the filename