Results 1 to 4 of 4
I want to search files in linux containing special text, for example:
I want to find any files in /etc containing text "10.0.0.3".
I just using command line (not the ...
- 03-06-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 3
Search files containing text
I want to search files in linux containing special text, for example:
I want to find any files in /etc containing text "10.0.0.3".
I just using command line (not the GUI interface),
how to solve this ?
thanks
- 03-06-2007 #2should do the trick.Code:
find /etc -type f -iname '*' -exec grep -Hni "10.0.0.3" {} \;
You could do like i did and put this in a bash script. Create a new file and in it put:
Save it, make it executable, then put it in /bin or somewhere in $PATH. Then when you run it use something like:Code:#!/bin/bash find "$1" -type f -iname '*' -exec grep -Hni "$2" {} \;
assuming you called it "findin" and it's in your $PATH somewhere, and you want to find instances of that IP in /etc.Code:findin /etc 10.0.0.3
Also being that it uses find, it is also recursive. So it will search all subdirectories in /etc. Also with the grep -Hni it will return the filename AND ilne number it found the text.
The format of the output is:
<text> is the whole text from that line of that file.Code:<filename>:<line number within file>:<text>
HTH"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
- 03-06-2007 #3
You can also do it just using grep.
will only check the files in /etc/itself;Code:grep "10.0.0.3" /etc/*
will check the files in /etc and all directories under /etc.Code:grep -R "10.0.0.3" /etc/*
Stand up and be counted as a Linux user!
- 03-07-2007 #4Just Joined!
- Join Date
- Mar 2007
- Posts
- 3
Thanks
Great, thanks a lot.


Reply With Quote