Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I think its a simple question, but the answer is probably a little more complicated :P

Edit: Actually, its not complicated at all!^^

So I have a directory with multiple svn projects and I would like to search through all recent files (in trunk folder) by content in all projects.

Here is somewhat the folders look like:

Projects
|
->Project1
|   |
|   ->tags
|   |
|   ->trunk
|
->Project2
|   |
|   ->tags
|   |
|   ->trunk
...
share|improve this question
3  
grep -l some-pattern ./Projects/Project*/trunk/*? Or more specific requirements? –  grebneke Mar 4 at 13:26
    
well the projects aren't really named ProjectX, but I guess ./Projects/*/trunk/* should do :) –  Alko Mar 4 at 14:07

2 Answers 2

up vote 3 down vote accepted

As suggested in comments above:

grep -l some-pattern ./Projects/*/trunk/*

or recursively if there are subdirs under each trunk (and your grep supports -r):

grep -lr some-pattern ./Projects/*/trunk/
share|improve this answer
    
@StephaneChazelas - thanks for the edit. POSIX does indeed not specify a recursive option for grep. Also noted BSD grep man page says -r is deprecated in favour of -R. GNU and BSD grep support -R - are there still modern systems with a non-recursive grep? –  grebneke Mar 4 at 14:20
    
Note that BSD grep (except recent OpenBSD) is now a fork of an old version of GNU grep. With recent GNU grep, -r should be preferred over -R as it doesn't follow symlinks (BSD greps handle the symlink issues differently/better). The grep of most commercial Unices don't support -r. –  Stéphane Chazelas Mar 4 at 14:24
find . -name .svn -prune -o -path '*/trunk/*' -type f -exec grep pattern {} +
share|improve this answer
1  
-exec **grep** pattern, no? –  grebneke Mar 4 at 13:34
    
@grebneke, oops, yes sorry. Fixed. –  Stéphane Chazelas Mar 4 at 13:57
    
This works, but I think the solution in the comment is more generic. The svn vas just an example, but I'll probably need this for other dirs too :) + the output is colored, which is awsome! :P –  Alko Mar 4 at 14:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.