I have a svn local copy, i want to make a search on the string some_string.

$ grep some_string * -r
lang/en:some_string=Some string
lang/.svn/en:some_string=Some string

But if a go little further, it seems that first level hidden directories are excluded :

$ cd lang && grep some_string * -r
en:some_string=Some string

How can I remove the hidden svn diretories from my output, and not only from the first depth level?

$ grep some_string * -r --which_option_here?
lang/en:some_string=Some string
  • Not a direct answer, but you may want to try ack. – depquid Oct 1 '14 at 14:13

Use --exclude-dir option, e.g.:

grep -r --exclude-dir='.*' some_string

From man grep:

              Exclude directories matching the pattern DIR from recursive searches.

Note however, that --exclude-dir option is available only in GNU grep. If your grep doesn't support it, you may need to use other tool as find for example:

find . \( -name .svn -prune \) -o -name "*" -exec grep -H "some_string" {} 2>/dev/null \;
  • I must have a too old Linux... – MUY Belgium Oct 2 '14 at 14:41
  • I have edited the answer, try the find version if your grep doesn't support --exclude-dir. – jimmij Oct 2 '14 at 15:04
  • I have version grep version 2.5.1, and there is no --exclude-dir argument, and I have tried everything I thought of... – MUY Belgium Oct 6 '14 at 9:21
  • 1
    Second solution doesn't use --exclude-dir, have you tried it? – jimmij Oct 6 '14 at 10:02
  • I have "unreconized option" – MUY Belgium Oct 6 '14 at 13:12

I normally use this:

for e in $(find . -maxdepth 1 -type d); do echo ${e#\./}; done | grep -v '^\.'

${e%\./} will remove the first ./ and then grep removes everything that begins with a dot.

  • Code says e#, text says e% – Stephen Rauch Feb 23 '17 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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