Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Apr 25 '10 at 14:24

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

up vote 15 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"
share|improve this answer
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 – Ehtesh Choudhury May 25 '12 at 15:49
This works for finding directories as well. – Pratik Khadloya Jul 24 '12 at 17:03
find and ack behave differently since ack filters out a lot of results by default (contents of version control directories, compiled objects in a source repository) that would be included by find. The best hammer depends on the results you want. – Joshua Goldberg Jan 8 '15 at 22:05
Actually, it's apparently kind of tricky to get ack version 2 to behave like find. – Joshua Goldberg Jan 8 '15 at 22:10
ack -g REGEX

Print files where the relative path + filename matches REGEX

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .