How do I find all files containing a specific string of text within their file contents?
The following doesn’t work. It seems to display every single file in the system.
find / -type f -exec grep -H 'text-to-find-here' {} \;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do the following:
-r
or-R
is recursive,-n
is line number, and-w
stands for match the whole word.-l
(lower-case L) can be added to just give the file name of matching files.-e
is the pattern used during the searchAlong with these,
--exclude
,--include
,--exclude-dir
flags could be used for efficient searching:--exclude-dir
parameter. For example, this will exclude the dirsdir1/
,dir2/
and all of them matching*.dst/
:This works very well for me, to achieve almost the same purpose like yours.