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
• 2,190 points
2,943 views

2 answers to this question.

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
2 answers

How do I find all files containing specific text and rename in unix/linux

Hi, @Kal You can use this command below to ...READ MORE

answered Jul 2 in Linux Administration by Gitika
• 19,720 points

edited Jul 2 by Gitika 52 views
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
37 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 20 in Linux Administration by DareDev
• 6,810 points
12 views
0 votes
1 answer
0 votes
1 answer

How to Unblock SSH and FTP Access to Specific IP in Linux?

Firewalls(most of them) can either Reject or ...READ MORE

answered 5 days ago in Linux Administration by Archana
• 5,480 points
19 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,430 points
169 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,160 points
26 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,810 points
685 views