Solved

How to search for specific text in all files

Posted on 2001-07-31
7
182 Views
Last Modified: 2010-03-18
I am trying to find a way to search for part of an ip address in every file on a Mandrake box. What's the easiest or fastest way to do it?

For example, I want to look for 172.16.10. in all files and print them out verbosely.
0
Comment
Question by:phreakin
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Expert Comment

by:dorward
ID: 6338495
cd /
grep 172.16.10 * -r

If you are looking for a config setting, its probaly best to start in /etc instead of / as all the config stuff should be in there.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 6338636
find / -type f -exec grep 172.16.10 {} \;
0
 
LVL 3

Expert Comment

by:tdaoud
ID: 6340216

ahoffman's command is the way to go, you might want to add -H to the grep command to ahoffman's line so you will also get the file name and path that contains the string as follows:

find / -type f -exec grep -H 172.16.10 {} \;

Tarik
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 17

Expert Comment

by:dorward
ID: 6340330
tdaoud: What is wrong with a recursive grep from the top level directory?
0
 
LVL 3

Expert Comment

by:tdaoud
ID: 6341919

dorward,

I always knew to use the find command, this is the first time I know from you that grep has a -r option to recurse sub-directories.

To tell you the truth all I wanted is to add to ahoffman's comment which would have been my answer too the option that displays the file name along with the output.

My appologies if my comments affected this question in any way.

Tarik
0
 
LVL 17

Expert Comment

by:dorward
ID: 6341993
I stuffed one random data in a file:

[david@mort ttt]$ grep 123 * -r
as/ere:123
[david@mort ttt]$
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6342287
-H and -r (respective -d recursive) are options known to grep version > 2.3. Also this is for GNU grep only.

So, my solutions works for any grep, independent of its version and/or platform. If you like to have the filename too, use -l option (also independent of ..). To get the path instead of the filename, the find command must be somehow trickier ;-)

Well, I'm picky again, please don't punish me ..
phreakin didn't give any linux/kernel/grep/shell version, so I posted this general purpose version, even if phreakin's system might do it somehow simpler with other options.
Does this answer all your questions?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question