The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Recursive grep upstate_boy UNIX for Dummies Questions & Answers 16 05-18-2008 02:16 PM
Script problem due to recursive directories Help please robertmcol Shell Programming and Scripting 2 04-27-2008 04:00 PM
recursive chmod that only affects directories? retrovertigo UNIX for Advanced & Expert Users 1 06-22-2007 01:02 PM
recursive grep issue Mace UNIX for Dummies Questions & Answers 1 08-11-2006 04:39 AM
recursive GREP ? alan UNIX for Dummies Questions & Answers 3 08-22-2003 12:15 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-22-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Question grep recursive directories

I am trying to locate a file or files with specific data in them. Problem is the file(s) could reside in any one of many directories.

My question is. Is there a way of recursively greping directories for the file(s) with the data I am looking for.

I have tried -
1.
$HOME> grep 47518 | ls -R > results

2.
$HOME> ls -R > grep 47518

3.
$HOME> ls -R | grep 47518

Help please!!!
Forum Sponsor
  #2  
Old 07-22-2003
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
pipe the results of 'find' to 'grep'.

a simple example would be you want to find all files on your system that contain the word 'unix'.

do this with:

find / | grep unix ( optionally: | less )
  #3  
Old 07-22-2003
Registered User
 

Join Date: Aug 2001
Posts: 179
try this....
find . | xargs grep whatever
  #4  
Old 07-22-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
By George it works !!!!

find . | xargs grep -s 47518

Great stuff thanks sssow
  #5  
Old 07-23-2003
davidg's Avatar
Registered User
 

Join Date: Jul 2003
Location: Holland
Posts: 207
Hhhm, want to add one more option :

find /my/dir/to/start -name \*pattern -exec grep text {} \;

Example :

find /tmp -name \*ipt -exec grep pall {} \; -exec ls -l {} \;
echo "He pall, please log of asap !!!"
-rwxr-xr-x 1 root sys 183 Jul 17 15:47 /tmp/script
server1:/root/home 1#

@yourservice
David
  #6  
Old 07-23-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Question

If this could be explained, I might see if I can use it.
At this stage I do not know what this command is doing.
The explaination of each part would be great.

Thanks.
  #7  
Old 07-24-2003
davidg's Avatar
Registered User
 

Join Date: Jul 2003
Location: Holland
Posts: 207
Hi,

Sorry, I will try to make things a bit more clear :

find /tmp -name \*ipt -exec grep pall {} \; -exec ls -l {} \;

The find command you probably know. It searches for files or directorys where you want him to search and to what pattern to match.

So :
"find /tmp" says only start searching in /tmp
"-name \*ipt" says to look for a file or directory ending with "ipt" the \ before the star says to not look for a file or directory named "*ipt" but to make it a pattern
"-exec grep pall {} \;" says that the result of find in /tmp with the pattern ending on "ipt" should do the following : "grep pall /tmp/script" so {} \; is replaced with the current result. It's hard to explain the syntax, I think you should just take this as it is and copy the syntax when you need it
"-exec ls -l {} \;" has the same syntax and executes the ls -l command for the current result. If you don't do this last -exec you don't know what file he grep the text from.

Hope you understand it know. Don't forget there is always a man page from find. I know it is large, but there is so much beautifull to explore in the man from find !!

@yourservice
David
Google The UNIX and Linux Forums
Closed Thread

Tags
grep, grep recursive, recursive grep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0