Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my ack --ignore-dir work?

Tags:

search

ack

I'm trying to search my entire server for a string, whilst excluding dev/ (-R) using ack. So far I have

sudo ack -i --ignore-dir=dev * foo

--version ack v1.39 

But I'm getting an error. Where am I going wrong?

Any help or advice on this matter is welcome

like image 374
edev.io Avatar asked Dec 26 '22 13:12

edev.io


1 Answers

First, whenever you say "I'm getting an error", change that to "I am getting the following error" and then tell us what the error is. The error is important for us to be able to help diagnose the problem.

Second, the version of ack you're using is very old. The latest is 1.96.

Third, you have your arguments out of order. You're searching for "foo", right? Then you should be doing "ack foo *", not "ack * foo".

You shouldn't be specifying "*" for a filename. Let ack do the file finding for you. If "dev" is a directory in the directory you're calling from, then "ack *" will expand to "ack dev [other directories]", which is explicitly telling ack to search in the "dev" directory, which overrides the --ignore-dir directive.

What you should be doing is:

ack -i --ignore-dir=dev foo

And then you let ack do the file finding. You should only specify filenames on the command line if for some reason you have to override the files that ack is finding.

Finally, you probably shouldn't even be using ack for this task in the first place. ack is specifically for searching source code, and it won't search files that it doesn't consider source code. If you are searching the entire server, then you probably want to be searching non-source code files, too, right? Use grep for this.

like image 69
Andy Lester Avatar answered Jan 05 '23 16:01

Andy Lester