Solved

How to search for specific text in all files

Posted on 2001-07-31
7
181 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux CentOs 6.7 : i can't start service 8 87
RaspBerry pi 2 model B problem: SSH Keys for the Common User - problem with key chain 7 68
Cron jobs 12 135
Video Streaming 6 85
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…

808 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