Can ack find files based on filename only?

Suan picture Suan · Oct 8, 2011 · Viewed 13.4k times · Source

Using ack (sometimes packaged as ack-grep) I know that I can find paths that contain a specific string by doing:
ack -g somestring

But what if I only want files which have "somestring" in their filenames?

Answer

user2141650 picture user2141650 · Mar 6, 2013

I agree find is the way to go, but you could also easily do it with ack:

ack -f | ack "string"

Here, "ack -f" recursively lists all the files it would search; pipe that to the second ack command to search through that. ack -f does have the advantage of skipping over binaries and directories even without any more arguments; often, then a "find" command could be replaced by a much shorter "ack" command.