text search
hi all
i want a search a text match, means a word it may be somewhere in some file. for example assume a user name is test1 if i type: find / -name test1 it should search all files having this line (test1) match i think the text (test1) should be somewhere in /etc/passwd Thanks in Advance jnreddy |
Quote:
1. if you are searching a file with a given name, then you can use the "find" command available in linux 2. if you are looking for a file that contains some specific words i.e you want to look inside the file then make use of "grep/rgrep/fgrep etc" which does the job. If you are looking for someting else do let us know, may be you want to write some scripts/wrappers using the above mentioned commands. do let us know what exactly you want then we'll be in a better positon to help you out. thank you. |
find and grep
If you need to looking for a file with word "test1" you can use:
find / -name "*test1*" Other wise if you need to look for a certain text on specify file you can use: grep -i "test1" /etc/passwd It will look for the word test1 on file /etc/passwd Now if you prefer combine both, Ex. search on directory /home/test all file txt that have "test1" word in in, do: $ grep test1 `find /home/test/*.txt -name "*.txt"` I hope this will help you |
Combine find and grep to find files that contain a specific word or phrase:
Code:
find /home/dis -type f|grep -l "Test data" However, it should be noted that, if this string is not on the same line, then the file would not be found (and of course you need permissions to read the file for the grep statement to work) |
Quote:
|
Still probs
Thanks to allez,Disillutionist,olilogu,harry2006
I want to find files that contain a specific word or phrase i just created a file with vi editor vi test1, then i inserted a word named monkey in that,so test1 file contains a string called monkey. i tried below command to search that string monkey. find / -type f|grep -1 "monkey" it doesn't find the string Thanks In Advance jnreddy |
Quote:
Try this command: Code:
find / -type f -exec grep -l "monkey" {} \; |
That should be a lower case L character in the grep statement, not a number.
Also I would suggest not running find from / as you are likely to get a large amount of permission denied messages (unless you're running as root) |
sorry,still prob
Thnkq allez disillutionist
am extremely sorry for improper observation did not notice that 1(ell) or l.(one). now i tried the command but unfortunately am facing this err and also i tried with uppercase L(ell) i got the same error. [root@server1 ~]# find / -type f -exec grep -l "monkey" {} \; grep: /var/named/chroot/proc/acpi/event: Device or resource busy grep: /var/named/chroot/proc/sys/net/ipv6/route/flush: Operation not permitted grep: /var/named/chroot/proc/sys/net/ipv4/route/flush: Operation not permitted grep: /var/named/chroot/proc/sysrq-trigger: Invalid argume cursor is continously blinking for ever? Thanks In Advance jnreddy |
Assuming that you have the syntax right, is it possible that there is something about those files that makes them do strange thing with GREP? (Try it and see.)
Repeating earlier advice: You do not normally want to run find starting at the root directory (/). Use something like /home or /usr (or wherever the files are that you want to test). |
Quote:
The proc folder structure enables interaction with hardware and kernel functions and should not be treated as you would normal files. |
problem resolved
Thanks to all of them, who spent their valuable time to give support to resolve this issue.
as you said i tried with /home. find /home -type f -exec grep -l "monkey" {} \; Thanks in advance jnreddy |
Use the command grep -ri "keyword_you_are_looking_for" <locations_you_want_to_search_for_this_keyword>
This should do the trick. :) Linux Archive |
All times are GMT -5. The time now is 10:31 PM. |