How to search for particular file?
Page 1 of 1 • Share •
How to search for particular file?
How to search for particular file that contains a few keywords?(remember i am not talking about file names)
in windows search there is this option that can search the content ,how to do it in Linux
in windows search there is this option that can search the content ,how to do it in Linux

Ramprasadg- Posts: 12
Join date: 2008-08-13
Re: How to search for particular file?
probably u've to use find(1) along with grep(1)....
a sample could be...
the above shell sequence searches in each file whose name matches *.txt under the directory /home/ram... and prints the filename if it contains "great" pattern in it....
remember... find(1) is recursive... i.e it searches the sub directories as well.....
or a better version of the above example could be....with grep(1)'s -l option which is used to print just the filenames instead of the lines which match the given regular expression....
i.e
Hope that helps.....
a sample could be...
- Code:
for i in `find /home/ram -name "*.txt" -print`
do
if grep great $i 1>/dev/null 2>&1
then
echo $i
fi
done
the above shell sequence searches in each file whose name matches *.txt under the directory /home/ram... and prints the filename if it contains "great" pattern in it....
remember... find(1) is recursive... i.e it searches the sub directories as well.....
or a better version of the above example could be....with grep(1)'s -l option which is used to print just the filenames instead of the lines which match the given regular expression....
i.e
- Code:
$ grep -l <regExp> `find /home/ram -name "*.txt" -print`
Hope that helps.....
vijay- Posts: 6
Join date: 2008-08-18
Re: How to search for particular file?
consider this...
Search pattern - abc
filename - <whatever>
if i use $grep <search pattern> <filename>, it will list all the occurences of abc anywhere in the line of file
like the entries "xyzabc123" and "abc" alone would result in the finding of abc pattern. But what i can get from the problem is that i have to search for the abc pattern alone.
above example would search twice for this pattern however the command should have reported only one single occurence
Search pattern - abc
filename - <whatever>
if i use $grep <search pattern> <filename>, it will list all the occurences of abc anywhere in the line of file
like the entries "xyzabc123" and "abc" alone would result in the finding of abc pattern. But what i can get from the problem is that i have to search for the abc pattern alone.
above example would search twice for this pattern however the command should have reported only one single occurence

Beagle- Posts: 9
Join date: 2008-08-12
grep -e
considering ur file name to be a.txt and content to be searched is abc
this command will do it :
grep -e [[:space:]]abc[[:space:]] a.txt
-e is used to specify the pattern to be a regular expression.
this will print the whole line . u can print jus the filename using -l option.
this command will do it :
grep -e [[:space:]]abc[[:space:]] a.txt
-e is used to specify the pattern to be a regular expression.
this will print the whole line . u can print jus the filename using -l option.
csbhagav- Posts: 3
Join date: 2008-08-18
A program with gui ( beagle )
name: beagle
for more details http://linuxappfinder.com/blog/linux_desktop_search
please continue the discussion...
for more details http://linuxappfinder.com/blog/linux_desktop_search
please continue the discussion...

Ramprasadg- Posts: 12
Join date: 2008-08-13
Re: How to search for particular file?
grep -l 'pattern' *
this will give the names of all the filenames containing the pattern
this will give the names of all the filenames containing the pattern
ankitgr8- Posts: 6
Join date: 2008-08-11
Re: How to search for particular file?
Plzz add few more questions ..and continue the topic!! 
Gyanendra- Posts: 8
Join date: 2008-09-07
Permissions of this forum:
You cannot reply to topics in this forum





