Search code examples
ack

Why might ack miss files that grep finds?


Consider this result on an Ubuntu Server machine:

 - awsZeta():postfix$ ack virtual
 - awsZeta():postfix$ ack -r virtual
 - awsZeta():postfix$ grep -r virtual *
main.cf:# this specifies where the virtual mailbox folders will be located
main.cf:virtual_mailbox_base = /var/spool/mail/virtual
main.cf:virtual_mailbox_maps = mysql:/etc/postfix/mysql_mailbox.cf
main.cf:virtual_alias_maps = mysql:/etc/postfix/mysql_alias.cf
main.cf:virtual_mailbox_domains = mysql:/etc/postfix/mysql_domains.cf
main.cf:# this is how to connect to the domains (all virtual, but the option is there)
main.cf:virtual_uid_maps = static:5000
main.cf:virtual_gid_maps = static:5000
master.cf:virtual   unix  -       n       n       -       -       virtual
master.cf:#  virtual_transport = lmtp:inet:localhost
postfix-files:$daemon_directory/virtual:f:root:-:755
postfix-files:$config_directory/virtual:f:root:-:644:p1
postfix-files:$manpage_directory/man5/virtual.5:f:root:-:644
postfix-files:$manpage_directory/man8/virtual.8:f:root:-:644
postfix-files:$sample_directory/sample-virtual.cf:f:root:-:644:o
postfix-files:$html_directory/virtual.5.html:f:root:-:644
postfix-files:$html_directory/virtual.8.html:f:root:-:644
 - awsZeta():postfix$ ack --version
ack-grep 1.92
Running under Perl 5.14.2 at /usr/bin/perl

Copyright 2005-2009 Andy Lester.

This program is free software; you can redistribute it and/or modify
it under the terms of either: the GNU General Public License as
published by the Free Software Foundation; or the Artistic License.

Why might ack have missed these results? How might I get ack to behave like grep -r foobar *, which it ostensibly does? Might this be due to the pre- 2.0 Ack version in use?


Solution

  • Yes, it's because you're using pre-2.0 ack.

    ack 1.x only searches known file types that are known to be source code. It's not a general purpose replacement for grep.

    ack 2.x by default searches any text file that it finds, whether or not it is of a known source code type, like .c or .php.

    From http://beyondgrep.com/ack-2.0/

    When no selectors are specified, ack 1.x only searches through files that it can map to a file type. ack 2.x, by constrast, will search through every regular, non-binary file that is not explicitly ignored via --ignore-file or --ignore-dir. This is similar to the behavior of the -a/--all option in ack 1.x.