ack(ack-grep) to ignore nested-directories

800 Views Asked by At

i have ubuntu 14.04. and using ack-grep 2.12 to search for a text in files recursively inside a directory

I want to setup ack-grep options specific to the directory ~/workspace/project/ so that when i am at path ~/workspace/project and do ack 'mypattern' it search recursively in all child and grand-child directories,, and in all files recursively. and print the results. Further i have some child directories and also some grand child directories to ignore all files inside of them.

currently i am having a file .ackrc as ~/workspace/project/.ackrc

where i have written

  --ignore-directory=is:node_modules/
  --ignore-directory=is:public/bower_compoenents/

Now when i search ack-grep 'hello' it also searches in all the directories which i have instructed to IGNORE from .ackrc

Even using this pattern inside the .ackrc, it again searches in to be ignored directories. (PS : this works perfectly in the mac os x [EDIT : probably with an older version of ack])

  --ignore-dir=node_modules/
  --ignore-dir=public/bower_compoenents/

further none of these worked so far

--ignore-dir=public/bower_components --ignore-dir=is:public/bower_components

Am i doing anything wrong?

EDIT : looking for resolution to ignore searching in nested directory. (i do not want to supply any special option while executing ack-grep on command line)

2

There are 2 best solutions below

5
On

Quoting from the ack 2.12 manual:

--[no]ignore-dir=DIRNAME, --[no]ignore-directory=DIRNAME

Ignore directory (as CVS, .svn, etc are ignored). May be used multiple times to ignore multiple directories. For example, mason users may wish to include --ignore-dir=data. The --noignore-dir option allows users to search directories which would normally be ignored (perhaps to research the contents of .svn/props directories).

The DIRNAME must always be a simple directory name. Nested directories like foo/bar are NOT supported. You would need to specify --ignore-dir=foo and then no files from any foo directory are taken into account by ack unless given explicitly on the command line.

So it looks like you would need to drop the slashes and the nested directories.

Are you sure this works on your other machine? What version of ack is on that machine?

1
On

--ignore-dir=public/bower_compoenents should work if you invoke ack from the parent directory of "public". However, this may not work in Ubuntu's ack version if it is an old version (older than 1.93_02?). Download newer ack version (mine is 2.14).

See this thread:

Ignoring sub-directories in .ackrc