Why doesn't ack recursively search all files by default?

3

From everything I can read

ack-grep foo

should search through all files in the current directory and subdirectories for the term "foo".

However, the closest I can get is

ack-grep foo *

Which returns all results that have "foo" in the current directory.

Why does the first command not work? I use ack version 1.92.

theicfire

Posted 2012-08-07T21:08:43.147

Reputation: 243

Is your ack-grep the same as ack? If so, which version? – slhck – 2012-08-07T21:12:00.227

I symlinked ack to ack-grep. The verison is 1.92 – theicfire – 2012-08-07T21:16:12.787

Do you have ACK_OPTIONS set or an ackrc file? I.e. does it work with --noenv set? – slhck – 2012-08-07T21:22:44.830

Nothing from echo $ACK_OPTIONS | ~/.ackrc does not exit | ack-grep --noenv stuff does not work, while ack-grep --noenv stuff * does – theicfire – 2012-08-07T21:41:56.293

In general, you don't specify files on the command line with ack, which is what you're doing with ack foo *. When you specify files, then you're telling ack to not do any of its magic file selecting, which includes recursing into lower directories. – Andy Lester – 2012-08-08T12:22:59.523

Answers

3

It depends on what is actually in foo, or if you have told ack-grep to recognize it as a type

# using  ack-grep Version 1.92

mkdir junk; cd junk

echo 'hello' > wango
ack-grep hello       #  nothing found, because 'wango' is an unknown type

echo -e '#!/bin/bash\nhello' > wango
ack-grep hello       #  found, because '#!/bin/bash` identifies a known type
 wango
 2:hello

echo 'hello' > wango
ack-grep -a hello    #  found, because '-a' selects all files (almost all)
 wango
 1:hello

From man ack-grep

ack-grep is intelligent about the files it searches. It knows about certain file types, based on both the extension on the file and, in some cases, the contents of the file. These selections can be made with the --type option.

With no file selections, ack-grep only searches files of types that it recognizes. If you have a file called foo.wango, and ack-grep doesn't know what a .wango file is, ack-grep won't search it.

The -a option tells ack-grep to select all files, regardless of type.

Some files will never be selected by ack-grep, even with -a, including:

· Backup files: Files matching #*# or ending with ~.

· Coredumps: Files matching core.\d+

However, ack-grep always searches the files given on the command line, no matter what type. Furthermore, by specifying the -u option all files will be searched.

Peter.O

Posted 2012-08-07T21:08:43.147

Reputation: 2 743

1

Awesome! Thanks; I ran into this problem because I was using ack on coffeescript and handlebars; I didn't realize these files were special. I found a quick solution: http://effectif.com/coffeescript/using-ack-with-coffeescript

– theicfire – 2012-08-07T23:23:15.933