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,320 points
8,761 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, 2019 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, 2019 in Linux Administration by Gitika
• 26,310 points

edited Jul 2, 2019 by Gitika 121 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, 2019 in Linux Administration by Rishi
528 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, 2019 in Linux Administration by DareDev
• 6,850 points
95 views
0 votes
1 answer

How do I use a shell script to SSH in to a remote machine to execute commands?

Your first problem can be solved like ...READ MORE

answered Jun 27, 2019 in Linux Administration by ajs3033
• 7,280 points
177 views
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 Jul 16, 2019 in Linux Administration by Archana
• 5,600 points
1,322 views
+1 vote
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,940 points
661 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
• 57,530 points
64 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, 2019 by Frankie
• 9,810 points
1,962 views