I often use the find
command to search through source code, delete files, whatever. Annoyingly, because Subversion stores duplicates of each file in its .
Just thought I'd add a simple alternative to Kaleb's and others' posts (which detailed the use of the find -prune
option, ack
, repofind
commands etc.) which is particularly applicable to the usage you have described in the question (and any other similar usages):
For performance, you should always try to use find ... -exec grep ... +
(thanks Kenji for pointing this out) or find ... | xargs egrep ...
(portable) or find ... -print0 | xargs -0 egrep ...
(GNU; works on filenames containing spaces) instead of find ... -exec grep ... \;
.
The find ... -exec ... +
and find | xargs
form does not fork egrep
for each file, but rather for a bunch of files at a time, resulting in much faster execution.
When using the find | xargs
form you can also use grep
to easily and quickly prune .svn
(or any directories or regular expression), i.e. find ... -print0 | grep -v '/\.svn' | xargs -0 egrep ...
(useful when you need something quick and can't be bothered to remember how to set up find
's -prune
logic.)
The find | grep | xargs
approach is similar to GNU find
's -regex
option (see ghostdog74
's post), but is more portable (will also work on platforms where GNU find
is not available.)