![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
try this....
find . | xargs grep whatever |
|
#4
|
|||
|
|||
|
By George it works !!!!
find . | xargs grep -s 47518 Great stuff thanks sssow |
|
#5
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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 |
| Tags |
| grep, grep recursive, recursive grep |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|