How to ignore certain filenames using "find"?
Solution 1:
You can use the negate (!) feature of find to not match files with specific names:
find . ! -name '*.html' ! -path '*.svn*' -exec grep 'SearchString' {} /dev/null \;
So if the name ends in .html or contains .svn anywhere in the path, it will not match, and so the exec will not be executed.
Solution 2:
I've had the same issue for a long time, and there are several solutions which can be applicable in different situations:
-
ack-grep
is a sort of "developer'sgrep
" which by default skips version control directories and temporary files. Theman
page explains how to search only specific file types and how to define your own. -
grep
's own--exclude
and--exclude-dir
options can be used very easily to skip file globs and single directories (no globbing for directories, unfortunately). -
find . \( -type d -name '.svn' -o -type f -name '*.html' \) -prune -o -print0 | xargs -0 grep ...
should work, but the above options are probably less of a hassle in the long run.