Search code examples
shellcommand-lineack

How to ignore search through test files


I am using ack and I want to avoid searching through any file which has name test. How do I do that?

Following ensures that only search through files or directory with name test. I want reverse of it.

ack foo --rb -G test

Solution

  • ack -G '^(?!test$)'
    ack -G '^(?!.*test)'
    

    Use the first one to ignore files named exactly test. Use the second to ignore files with the word test anywhere inside.

    If you want to permanently ignore test files you could edit the is_searchable function in the ack script. This is the routine which filters out core dumps, swap files, and the like.