How do you exclude a specific file from ack (ack

With the normal grep command there is an --exclude option (covered in detail here: Use grep --exclude/--include syntax to not grep through certain files) that lets you ignore specific files when you are grepping.

Ack's --type option takes care of 95% of the cases where you'd want to exclude files, but it doesn't (as far as I can tell) handle the case of excluding a specific file. I've got a compiled JS file that has the contents of every other JS file in it (on a single line), so every time I grep for anything I get back the entire contents of that giant compiled file.

I'd hate to have to give up on ack and go back to grep over this, but it is really annoying. Please, someone tell me there's a way to exclude specific files from ack searches.


No, ack 1.x will not let you exclude a single file. In ack 2.0, you can. ack 2.0 was currently in its first alpha is now the current recommended version of ack.

As far as your specific case of the minified Javascript file, what version of ack are you using? ack 1.96 should ignore minified JavaScript based on extension. If the extension check doesn't work, you could probably hack ack itself, since it's a single Perl program. You can hack the is_searchable function.

In ack 2.0, we're looking at ignoring any line over, say, 500 characters because it's clearly not source code.

You may also want to join us on the ack-users mailing list. We're pretty responsive.


要使用ack 2.0忽略单个文件,请为--ignore-file标志提供一个过滤器规范:

--ignore-file=is:cljout.js


If you run ack --create-ackrc it will output a whole bunch of presets for common files like minified javascript, css and directories like node_modules and .git. Very useful!

Here's the minified js option:

# minified Javascript
--ignore-file=match:/[.-]min[.]js$/
--ignore-file=match:/[.]js[.]min$

If you want to save this to .ackrc run

ack --create-ackrc >> ~/.ackrc

and then delete what you don't need from that file.

链接地址: http://www.djcxy.com/p/47244.html

上一篇: grep排除文件名称模式

下一篇: 如何从ack中排除特定文件(ack