You can use
ack -hc
(-h
being shorthand for --no-filename
) to get a total count.
According to the ack documentation/man page:
-c, --count
Suppress normal output; instead print a count of matching lines for each input file. If -l
is in effect, it will only show the number of lines for each file that has lines matching. Without -l
, some line counts may be zeroes.
If combined with -h
(--no-filename
) ack
outputs only one total count.
Here's what worked for me (expanding on @Jordan's answer) --
ack 'pattern' && ack -hc 'pattern'
or, better (IMO):
ack 'pattern'; ack -hc 'pattern'
As far as I understand, using &&
, the second command depends on the first one returning to run; using ;
instead will just run them both, one after the other, regardless. In this case, I think the ;
is more appropriate.