Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I find all files containing specific text within the file on Linux?

I'm trying to find a way to scan my entire Linux system for all files containing a specific string of text.
I'm looking for text within the file, not in the file name.

When I was looking up how to do this, I came across this solution twice:

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

However, it doesn't work. It seems to display every single file in the system.

Is this close to the proper way to do it? If not, how should I?
by

2 Answers

Kajalsi45d
You can utilize grep - ilR:
grep -Ril "text-to-find-here" /

i represents overlook case (discretionary for your situation).
R stands for recursive.
l means "show the document name, not simply the outcome".
/ represents beginning at the root of your machine.
Shahlar1vxp
The code for finding all the files is as follows-
find/-type f-exec grep -H 'text-to-find-here' {}\;
In this case, find is the standard tool for searching all files which are combined with grep when you look for a specific text on platforms like Unix. This command is usually combined with xarqs.
The other way is by using 'pwd' to search from any directory you are moving in. The code is as follows-
grep- rnw 'pwd' -e"pattern"

Login / Signup to Answer the Question.