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?

link|improve this question

50% accept rate
feedback

migrated from stackoverflow.com Apr 25 '10 at 14:24

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 7 down vote accepted

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"
link|improve this answer
1  
very true. "once you hold a hammer in your hand everything starts to look like a nail" :) – akira Apr 25 '10 at 15:05
Well, ack (and grep) are nicer because you don't have to be explicit about regexes unless you want to. I usually just do a find . | ack whatev.ext – shurane May 25 at 15:49
feedback
ack -g REGEX

Print files where the relative path + filename matches REGEX

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.