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

0 votes

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

When I was looking up how to do this :

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

However, it is working. It display every single file in the system.

Is this close to the proper way to do it? If not, how should I? This ability to find text strings in files would be useful for some programming concepts.

Jul 13, 2018 in Linux Administration by ArchanaNagur
• 1,790 points
2,089 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

To display all files containing specific text, you need to fire some commands to get output. lets see which would be helpful.

You can use “grep” command to search string in files. Alternatively, You can also also use the "find " command to display files with specific string.

Syntax is:

grep -rwl “search-string” /path/to/serch/dir

Lets See examples,

grep -rlw "tecadmin" /var/log

/var/log/lfd.log
/var/log/cloud-init.log
/var/log/messages-20170226
/var/log/audit/audit.log.1
/var/log/btmp-20170315
/var/log/httpd/access_log-20170226

Hope this answer help you.

answered Jul 13, 2018 by Fairyprincess
• 160 points

edited Jul 13, 2018 by Fairyprincess
0 votes


grep -rnw 'text to find recursively inside all file in current directory-by ritesh '   

grep -rnw '/path/to/somewhere/ritesh' -e 'text to find recursively inside all file '
answered May 20 by Ritesh Singh
What does -rnw stand for? What are those flags?
Hi @Ritesh.

What path should I give if I want to find the text in the whole file system?

Related Questions In Linux Administration

0 votes
1 answer
0 votes
1 answer

How to find path of software installed in Linux?

There are multiple ways to find the ...READ MORE

answered May 19 in Linux Administration by Rishi
21 views
0 votes
1 answer

How to display a simple list of all disks, like this /dev/sda /dev/sdb ?

You can list all the disk in ...READ MORE

answered Jul 12, 2018 in Linux Administration by DearestOne
• 200 points
85 views
+1 vote
3 answers
0 votes
1 answer
0 votes
1 answer

How to get octal file permission in linux?

You can use this: stat -c "%a %n" ...READ MORE

answered Jan 3 in Linux Administration by Omkar
• 66,910 points
59 views
0 votes
1 answer

Unable to access Jenkins. I newly installed Jenkins but for some reason I cannot access it.

Try changing the port, Change JENKINS_AJP_PORT="xyz" to JENKINS_AJP_PORT="abc" If changing the ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 9,330 points
126 views
0 votes
1 answer

Examples for string find in Python

you can use str.index too: >>> 'sdfasdf'.index('cc') Traceback ...READ MORE

answered Aug 29, 2018 in Python by Priyaj
• 56,140 points
25 views
0 votes
1 answer
0 votes
1 answer

Grep across multiple files in Hadoop

You are looking to applying to grep ...READ MORE

answered Jan 7 by Frankie
• 9,710 points
525 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.