How do you exclude a specific file from ack (ack-grep)?

ack ignore-directory
ack directory
ack print only match
ack 30
ack filenames
ack terminal command
ack case sensitive
ack count

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 Cheat Sheet, If any files or directories are specified, then only those files and directories are checked. ack may also search STDIN , but Default switches may be specified in the ACK_OPTIONS environment variable or an .ackrc file. Ignore case distinctions in pattern, but only if pattern contains no upper case b(?:ba|t?c|k|z|fi​)?sh\b/. Ack does almost all that grep does, but it differs in the following ways. Ack was designed to: Search directories recursively by default; Easily exclude certain file types or only search for certain file types; Ignore the common version control directories by default; these are directories with names like: .git, .gitignore, .svn

To ignore a single file using ack 2.0, provide a filter spec to the --ignore-file flag:

--ignore-file=is:cljout.js

ack documentation, File listing actions: -l, --files-with-matches Print filenames with at least one match -​L, -I, --no-ignore-case Turns on case-sensitivity in PATTERN. File presentation: --pager=COMMAND Pipes all ack output through COMMAND. b​(?:ba|t?c|k|z|fi)?sh\b/ --[no]smalltalk .st --[no]smarty .tpl --[no]sql .sql .ctl --[no]stylus .styl  Not that ack doesn’t have some advantages, but some that you mention grep can actually do. For example, -n adds line numbers, --exclude-dir=akismet will ignore a directory, -l will list just the files. For checking only php files, --include=*.php* will check in .php files as well as

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.

THE .ackrc FILE, Why isn't ack finding a match in (some file)?; Wouldn't it be great if ack did search & replace? The default options for ack ignore certain files and directories. As you can see, this gives you the matching parameters for each file type. You can also tell ack to exclude files of a certain category by preceding a type with “no”. So we could see the number of C language files we have by typing: ack -f --cc | wc -l

Also good to know with ack2.0, you can specify these options in a .ackrc file if you have to frequently filter files.

How do I ack-grep exclude file type *.sql files or file size larger than , I don't know about ack-grep but you can use find to exclude files larger than 3MB. find . -size -3M -exec grep "foo" {} \;. How can I use ack to search in files of a specific file type. For example ack -f .scss blah acl -f .rb blah Obviously the above does not work but how can I do this with ack?

If you want to exclude specific folder, following command may help you:

ack keywords --ignore-dir folder_name

man ack will provide further details :)

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

--ignore-file=FILTERTYPE:FILTERARGS

ack - grep-like text finder, ack is designed as an alternative to grep for programmers. ack searches the named input files or The default options for ack ignore certain files and directories. Example: --type-set make:match:/(gnu)?makefile/ firstlinematch:​PATTERN  File Selection. ack is intelligent about the files it searches. It knows about certain file types, based on both the extension on the file and, in some cases, the contents of the file. These selections can be made with the --type option. With no file selections, ack only searches files of types that it recognizes.

ack-grep - grep-like text finder, The default options for ack ignore certain files and directories. However, ack-​grep always searches the files given on the command line, no matter what type. Example: --type-set make:match:/(gnu)?makefile/ firstlinematch:PATTERN  ack is a grep-like source code search tool. The latest version of ack is v3.3.1, released 2020-01-13. Designed for programmers with large heterogeneous trees of source code, ack is written in portable Perl 5 and takes advantage of the power of Perl's regular expressions.

ack - grep-like text finder, Why isn't ack finding a match in (some file)?; Wouldn't it be great if ack did search & replace? The default options for ack ignore certain files and directories. If for some reason the package you're using installs ack as ack-grep, here's what to do. On Debian-derived distros, ack is packaged as "ack-grep" because "ack" already existed. If you simply install via: $ sudo apt-get install ack-grep your ack will be called "ack-grep", which is 167% more characters to type per invocation.

ack(1): grep-like text finder, Ack is designed as a replacement for 99% of the uses of grep. However, ack always searches the files given on the command line, no matter what type. However, it will ignore the shadow directories used by many version control systems, and the build directories used by Why isn't ack finding a match in (​some file)?. With a clever arrangement of syntax, you can use find’s faster file-system search to locate the specific file types you want to search within, then pipe them to grep in order to search inside the files. Note that find only looks at filenames, not contents. That’s why grep is required to search file text and contents.

Comments
  • In fact, my next stop was going to be the ack mailing list, but I figured I'd check here first to make sure I wasn't missing something obvious :-) Thanks Andy.
  • P.S. I'm choosing the filename for my compiled JS file, so at the moment it's just built.js. I'll try renaming it to built.min.js and see if that helps.
  • What is the is: doing here?
  • Exact filename match. beyondgrep.com/documentation/ack-2.04-man.html#is_filename
  • This works for me on filenames, but not if I want to give a specific file (i.e. path and filename).
  • You can use match along with a regex to match filenames and ext for extensions. Exclude js files --ignore-file=ext:js. Exclude files with name foo and bar --ignore-file='match:/foo|bar/'. Escape the parameter with quotes in case of regex with | so that shell doesn't execute it as a pipe.
  • This whole is: thing is so not obvious and annoying