How to use ack to search for file name

ack -g REGEX

Print files where the relative path + filename matches REGEX


Use the right tool for the right job. If you want to search for filename, use 'find':

$ # search for all *.txt file in current directory
$ find . -iname "*.txt"

I agree it makes sense to use find if you're just searching for *.txt files. However, ack has powerful file-type detectiong features, so you can use

ack -f --perl

which will find all the Perl files, based on both the filename (*.pm, *.pl, *.t and *.pod) and the shebang line.