LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 02-28-2011, 04:29 PM   #1
timdvtemp
Member
 
Registered: Feb 2011
Distribution: Redhat/Fedora
Posts: 39

Rep: Reputation: 3
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
 
Old 02-28-2011, 04:49 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,814

Rep: Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001Reputation: 1001
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grep Recursive Search Results Send To E-mail or Log? Knucklehead00 Linux - Newbie 2 06-05-2009 11:19 AM
Recursive directory search janel10 Linux - Newbie 2 08-26-2008 07:28 AM
recursive grep xpucto Solaris / OpenSolaris 2 05-29-2007 10:57 AM
Recursive grep jimieee Linux - General 5 10-06-2003 11:13 AM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 05:49 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration