LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Grep Recursive search directory depth option? (http://www.linuxquestions.org/questions/linux-software-2/grep-recursive-search-directory-depth-option-865563/)

timdvtemp 02-28-2011 03:29 PM

Grep Recursive search directory depth option?
 
I know grep can search recursively (ie through all subdirectories to the bottom of the directory tree), but is it possible to ask grep to only search say, 3 levels down? That means the current directory, any directories in the current directory, and within any directories within those?
Sounds confusing, but the problem is quite simple. Is the solution?
Thanks

corp769 02-28-2011 03:49 PM

Maybe using find along side of grep?
Code:

grep text `find . -maxdepth 3 -type f`
This example will find the text "text" within all files found, with the max depth of three directories. I know this isn't exactly what you need, I'm sure you can work with it and figure something out. I would fix it up for you myself, but I'm at work and I don't have access to linux currently.

Cheers,

Josh


All times are GMT -5. The time now is 11:26 AM.