Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Fedora 10[Cambridge] and Ubuntu 9.04[Jaunty]
Posts: 201
Rep:
Quote:
Originally Posted by jnreddy
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
You are not clear about what exctly you want. as far as I know there are basically two things available by default for searching e.g
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.
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"`
Combine find and grep to find files that contain a specific word or phrase:
Code:
find /home/dis -type f|grep -l "Test data"
will produce a list of all files that contain the string 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)
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.
You should be more careful on reading others' posts. Or just use "copy-paste" method. And, of course, read man grep about -l option ("ell", not "one").
Try this command:
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.