Solved

How to search for specific text in all files

Posted on 2001-07-31
7
180 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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