LinuxQuestions.org
Visit the LQ Articles and Editorials section
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, 03: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, 03:49 PM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
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 10:19 AM
Recursive directory search janel10 Linux - Newbie 2 08-26-2008 06:28 AM
recursive grep xpucto Solaris / OpenSolaris 2 05-29-2007 09:57 AM
Recursive grep jimieee Linux - General 5 10-06-2003 10:13 AM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 04:49 AM


All times are GMT -5. The time now is 07:38 AM.

Main Menu
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