18

I have started using ack which is much faster than grep. However using ack I want to search for file name rather than file contents. Is there a way to do that?

quack quixote
  • 43,504
Nadal
  • 979

4 Answers4

25
ack -g REGEX

Print files where the relative path + filename matches REGEX

17

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"
Lie Ryan
  • 4,517
  • 3
  • 25
  • 27
9

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.

Andy Lester
  • 1,302
  • 7
  • 15
1

You can do :

ack -f | ack "filename.ext"