When i use the find command i use it with grep to find some pattern in files.
Usage:
find . -name "*.java" -exec grep "foobar" {] \; -print
If i want to search only in a specific directory (in the next example “source” ) i use :
find ./source -name "*.java" -exec grep "foobar" {] \; -print
But what if i want to exclude one or more sub directories from the search ?
The find man page gave us a answer and it looks ugly. Here is the solution:
find ./source \( -name directory -prune \) -o -name "*.java" -exec grep "foobar" {] \; -print
You have to exclude the directory by using the construction \( -name directory -prune \).
Very ugly
#1 by yogsototh on October 27, 2010 - 11:21 am
Quote
I use zsh and this is how I’d do it:
grep “foobar” ./source/**/*(.)
and for exclusion
setopt extended_glob
grep “foobar” ./source/**/*(.)~./source/directory/**/*
A bit slower but far more readable.
**/* to match all sub directories/files
**/*(.) to match all files in sub directories
PATTERN~EXCLUDE_PATTERN
#2 by Lakeisha on October 27, 2010 - 4:07 pm
Quote
Hello
Is it OK that I go a bit off topic? I’m trying to view your site on my iPod Touch but it doesn’t display properly, any suggestions? Thanks for the help I hope! Lakeisha x
#3 by bo on October 29, 2010 - 2:38 pm
Quote
I know that zsh has few big advances over other shells like bash, tcsh, ash. This looks great, must think about o move to zsh
Great intro on your website
, congratulations
#4 by bo on October 29, 2010 - 2:40 pm
Quote
I have to install a mobile theme, this theme doesn’t scale very well on iPod/iPhone
#5 by free movies online on December 8, 2010 - 5:36 pm
Quote
It is the second entry I read tonight. And I am on my third. Got to think which one is next. Thank you.