Given you want to exclude all files in a directory named `migrations`, you can add a condition to the `find` command:
<pre><code>find . -name "*.py" -type f <b>! -path '*/migrations/*'</b> -exec grep . {} \; | wc -l</code></pre>
Note that counting the number of lines is probably easier with [**`cloc`**](http://cloc.sourceforge.net/):
<pre><code>cloc <b>--not-match-d=migrations</b> .</code></pre>
This will then generate a summary like:
$ cloc --not-match-d='migrations' .
102 text files.
86 unique files.
38 files ignored.
github.com/AlDanial/cloc v 1.74 T=0.88 s (97.3 files/s, 42411.8 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
XML 2 11 32 33299
Python 63 619 273 2673
HTML 18 35 49 304
JavaScript 2 8 5 100
CSS 1 5 6 81
-------------------------------------------------------------------------------
SUM: 86 678 365 36457
-------------------------------------------------------------------------------
You can use the [`cloc`](https://github.com/AlDanial/cloc) utility which is built for this exact purpose. It reports each the amount of lines in each language, together with how many of them are comments etc. CLOC is available on Linux, Mac and Windows.
Usage and output example:
$ cloc --exclude-lang=DTD,Lua,make,Python .
2570 text files.
2200 unique files.
8654 files ignored.
http://cloc.sourceforge.net v 1.53 T=8.0 s (202.4 files/s, 99198.6 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Javascript 1506 77848 212000 366495
CSS 56 9671 20147 87695
HTML 51 1409 151 7480
XML 6 3088 1383 6222
-------------------------------------------------------------------------------
SUM: 1619 92016 233681 467892
-------------------------------------------------------------------------------