Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 02-28-2011, 04:29 PM   #1
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?
Old 02-28-2011, 04:49 PM   #2
LQ Guru
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Maybe using find along side of grep?
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.




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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:46 PM.

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