Solved

How to search for specific text in all files

Posted on 2001-07-31
7
176 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now