Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

grep for a file, excluding svn metadata directories and files (See related posts)

Grep for something, excluding the annoying svn metadata (.svn**)
The find piece could also be used for more general tasks -- just remove the pipe and take a look at the output to see if it will work for you.
I tried (and failed) to use the find to a path preserving copy from within a subdirectory in a checkout...though there must be a way.

find . -path '*/.svn' -prune -o -type f -print | xargs -e grep -I -n -e PATTERN

Comments on this post

allaryin posts on Apr 18, 2007 at 17:28
This works great, but not if you have spaces in filenames or directories. A slight improvement that is capable of handling dirs with spaces would be:

find . -path '*/.svn' -prune -o -type f -print0 | xargs -0 grep -I -n -e PATTERN
bangersnmash74 posts on Apr 24, 2007 at 08:38
I use this (seems to do the trick adequately):
grep -r PATTERN * | grep -v '/\.svn/'

You need to create an account or log in to post comments to this site.


Click here to browse all 4856 code snippets

Related Posts