Find files containing text


 
Thread Tools Search this Thread
# 1  
Old 11-13-2001
Find files containing text

How do I find the files containing some text.

eg. I want to find alll the files that contain the word 'hello'

grep hello * will give me only for the specific directory.

How do I find for entire system.

Thanks for help in advance..
# 2  
Old 11-13-2001
Wow, for the entire system will take quite some time... but here's one way:
(note: I piped it to a file, in case there's lots of hits. You can view the /tmp/bigsearch.log to see the outputs. Also, you'll get a lot of errors and be very limited in your search if it is not executed by root)
Code:
find / -type f -print | xargs grep "hello" >> /tmp/bigsearch.log 2>/dev/null

Hope that helps...

Also, it may slow your system considerably, depending on the power of your machine. I wouldn't recommend running that on a production or even needed box...
# 3  
Old 11-13-2001
when you use "grep -l" you obtain only names of the propper files ...
# 4  
Old 11-15-2001
Recursive Grep

and another useful way is to try this: grep -il "hello" `find .`


i find that another useful way of doing a recurvsive grep

find . -type f -exec grep -il "hello" {} \;

or if you know the file type

find . -type f -name "*.ext" -exec grep -il "hello" {} \

and/ or if you just want your files

find . -type f -user myname -name "*.ext" -exec grep -il "hello" {} \

and obviously you can still output this to a log file using the redirect >


I hope this helps
Shakey21
# 5  
Old 11-16-2001
What I suggest is much easier

try :

<pre>

grep whatever /*

</pre>

as simple as that.

That works with solaris !
# 6  
Old 11-16-2001
Easy is not the only objective. Effectivity is more important. I would come down hard on users who attempted to grep my 60 GB of files. Thanks to Shakey for showing the novices how to make their search more effective and less impacting.
Jimbo
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk to skip lines find text and add text based on number cmccabe Shell Programming and Scripting 6 02-17-2016 01:32 PM
Find text that is different in two files cmccabe Shell Programming and Scripting 8 05-27-2015 09:10 PM
Read text between regexps and write into files based on a field in the text r3d3 Shell Programming and Scripting 7 10-17-2013 10:55 PM
Search only text files with 'find' command? Collider Linux 2 09-08-2012 02:26 AM
How to find empty files in a directory and write their file names in a text? vel4ever Shell Programming and Scripting 1 02-06-2012 02:38 AM
Find and replace using 2 text files as arrays. Erulisseuiin Shell Programming and Scripting 2 06-12-2011 06:27 AM
How to find text in files without using the word itself but the assigned variable of it jenimesh19 Shell Programming and Scripting 7 03-08-2011 05:44 PM
Find and add/replace text in text files lodhi1978 Shell Programming and Scripting 6 02-11-2011 03:11 AM
Find text containing paths and replace with a string in all the python files noorsam Shell Programming and Scripting 5 09-20-2010 08:23 AM
Find all text files in folder and then copy to a new folder cgkmal Shell Programming and Scripting 4 06-20-2009 01:12 PM
Bash snippet to find files based on a text file? DJ Charlie Shell Programming and Scripting 14 04-02-2009 12:13 PM
find text but replace a text beside it The One Shell Programming and Scripting 4 09-02-2008 03:13 AM
sorting files with find command before sending to text file deking UNIX for Dummies Questions & Answers 6 07-20-2008 06:53 PM
find files where text case is different schipper Shell Programming and Scripting 5 04-26-2006 08:33 AM
How to find a text in jar and zip files.?? redlotus72 UNIX for Dummies Questions & Answers 1 03-07-2006 07:29 AM