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,360 points
40,410 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.

To learn more about Linux, enroll in Linux administration course online today.

Thanks.

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
• 65,770 points

edited Jul 2, 2019 by Gitika 2,729 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues copying a ...READ MORE

Apr 13, 2022 in Linux Administration by Soham
• 9,710 points
385 views
0 votes
0 answers

How do I output coloured text to a Linux terminal?

How do I print coloured characters to ...READ MORE

Apr 20, 2022 in Linux Administration by Edureka
• 13,690 points
424 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues to copy ...READ MORE

Apr 21, 2022 in Linux Administration by Edureka
• 13,690 points
409 views
0 votes
1 answer

How can I find out which files differ in two directory trees?

Use this; diff -qr dir1/ dir2/ READ MORE

answered Jun 13, 2019 in Linux Administration by Upasana
• 8,620 points
786 views
0 votes
0 answers

How do i select correct active serial port in linux?

I am trying to communicate with a ...READ MORE

Apr 13, 2022 in Linux Administration by Soham
• 9,710 points
570 views
0 votes
1 answer

How to find all files containing specific text on Linux?

Hi@akhtar, Linux systems have one interesting command name grep. ...READ MORE

answered Sep 22, 2020 in Linux Administration by MD
• 95,460 points
1,323 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
• 10,620 points
8,305 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
• 58,020 points
798 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP