56

My folder structure looks like this:

/app
/app/data
...
/app/secondary
/app/secondary/data

I want to recursively search /app, including /app/data. I do not want to search /app/secondary/data however. This what I have so far:

ack --ignore-dir=data searchtext
ack --ignore-dir=secondary/data searchtext

The first command is ignoring both directories and the second one is ignoring neither of them. From within the app folder, what should my ack command look like?

2 Answers 2

60

The older versions of ack can only take the folder name, not the folder path. As of version 1.93_02, they've added this ability in:

1.93_02     Wed Oct  6 21:39:58 CDT 2010
   [ENHANCEMENTS]
   The --ignore-dir option now can ignore entire paths relative
   to your current directory.  Thanks to Nick Hooey.  For example:

       ack --ignore-dir=t/subsystem/test-data

(From betterthangrep.com/Changes)

You can check which version you have with --version:

ack --version
1
  • Note that this option must be before the string to grep (e.g., ack --ignore-dir=foo/ 'bar', but not ack 'bar' --ignore-dir=foo/).
    – toku-sa-n
    Jul 23 at 1:41
23

This answer is for versions of Ack prior to 2, see This answer for versions of Ack >=2.

The first one is ignoring both because they both have 'data' as a sub-directory and ack searches sub-dirs by default. So it will ignore any sub-dir with that name. Unfortunately, your second way doesn't work either. This works for me:

ack -a searchtext -G '^(?!.*secondary/data.*).*$'

Instead of -a to search all files, see ack-grep --help=types to search for only certain file types, eg --type=text

5
  • Thanks for the response. I'm getting this: $ ack-grep --text -G '^(?!.*secondary/data.*).*$' ack-grep: No regular expression found.
    – mattalxndr
    May 10, 2010 at 3:44
  • that's because you forgot to give it the pattern you're grepping for, ie 'searchtext'
    – rkulla
    May 10, 2010 at 5:21
  • For information about how to put this -G option in a ~/.ackrc file, see: stackoverflow.com/questions/5425363/… Mar 24, 2011 at 21:52
  • 4
    $ ack -G Option '-G' is not valid in ack 2 Jan 13, 2014 at 17:23
  • how do we ask ack to do this forever, for example in a .ackrc file?
    – nyxee
    Jul 24, 2017 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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