Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

How to search for specific text in all files

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
phreakin
Asked:
phreakin
  • 3
  • 2
  • 2
1 Solution
 
dorwardCommented:
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
 
ahoffmannCommented:
find / -type f -exec grep 172.16.10 {} \;
0
 
tdaoudCommented:

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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
dorwardCommented:
tdaoud: What is wrong with a recursive grep from the top level directory?
0
 
tdaoudCommented:

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
 
dorwardCommented:
I stuffed one random data in a file:

[david@mort ttt]$ grep 123 * -r
as/ere:123
[david@mort ttt]$
0
 
ahoffmannCommented:
-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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now