ACK(1) User Contributed Perl Documentation ACK(1) NAME ack - grep-like text finder SYNOPSIS ack [options] PATTERN [FILE...] ack -f [options] [DIRECTORY...] DESCRIPTION ack is designed as an alternative to grep for programmers. ack searches the named input FILEs or DIRECTORYs for lines containing a match to the given PATTERN. By default, ack prints the matching lines. If no FILE or DIRECTORY is given, the current directory will be searched. PATTERN is a Perl regular expression. Perl regular expressions are commonly found in other programming languages, but for the particulars of their behavior, please consult perlreref . If you don't know how to use regular expression but are interested in learning, you may consult perlretut . If you do not need or want ack to use regular expressions, please see the "-Q"/"--literal" option. Ack can also list files that would be searched, without actually searching them, to let you take advantage of ack's file-type filtering capabilities. FILE SELECTION If files are not specified for searching, either on the command line or piped in with the "-x" option, ack delves into subdirectories selecting files for searching. 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 selection, ack searches through regular files that are not explicitly excluded by --ignore-dir and --ignore-file options, either present in ackrc files or on the command line. The default options for ack ignore certain files and directories. These include: o Backup files: Files matching #*# or ending with ~. o Coredumps: Files matching core.\d+ o Version control directories like .svn and .git. Run ack with the "--dump" option to see what settings are set. However, ack always searches the files given on the command line, no matter what type. If you tell ack to search in a coredump, it will search in a coredump. DIRECTORY SELECTION ack descends through the directory tree of the starting directories specified. If no directories are specified, the current working directory is used. However, it will ignore the shadow directories used by many version control systems, and the build directories used by the Perl MakeMaker system. You may add or remove a directory from this list with the --[no]ignore-dir option. The option may be repeated to add/remove multiple directories from the ignore list. For a complete list of directories that do not get searched, run "ack --dump". MATCHING IN A RANGE OF LINES The "--range-start" and "--range-end" options let you specify ranges of lines to search within each file. Say you had the following file, called testfile: # This function calls print on "foo". sub foo { print 'foo'; } my $print = 1; sub bar { print 'bar'; } my $task = 'print'; Calling "ack print" will give us five matches: $ ack print testfile # This function calls print on "foo". print 'foo'; my $print = 1; print 'bar'; my $task = 'print'; What if we only want to search for "print" within the subroutines? We can specify ranges of lines that we want ack to search. The range starts with any line that matches the pattern "^sub \w+", and stops with any line that matches "^}". $ ack --range-start='^sub \w+' --range-end='^}' print testfile print 'foo'; print 'bar'; Note that ack searched two ranges of lines. The listing below shows which lines were in a range and which were out of the range. Out # This function calls print on "foo". In sub foo { In print 'foo'; In } Out my $print = 1; In sub bar { In print 'bar'; In } Out my $task = 'print'; You don't have to specify both "--range-start" and "--range-end". IF "--range-start" is omitted, then the range runs from the first line in the file until the first line that matches "--range-end". Similarly, if "--range-end" is omitted, the range runs from the first line matching "--range-start" to the end of the file. For example, if you wanted to search all HTML files up until the first instance of the "", you could do ack foo --html --range-end='' Or to search after Perl's `__DATA__` or `__END__` markers, you would do ack pattern --perl --range-start='^__(END|DATA)__' It's possible for a range to start and stop on the same line. For example --range-start='' --range-end='' would match this line as both the start and end of the range, making a one-line range. Page title Note that the patterns in "--range-start" and "--range-end" are not affected by options like "-i", "-w" and "-Q" that modify the behavior of the main pattern being matched. Again, ranges only affect where matches are looked for. Everything else in ack works the same way. Using "-c" option with a range will give a count of all the matches that appear within those ranges. The "-l" shows those files that have a match within a range, and the "-L" option shows files that do not have a match within a range. The "-v" option for negating a match works inside the range, too. To see lines that don't match "google" within the "" section of your HTML files, you could do: ack google -v --html --range-start='. Shell and Return Code For greater compatibility with grep, ack in normal use returns shell return or exit code of 0 only if something is found and 1 if no match is found. (Shell exit code 1 is "$?=256" in perl with "system" or backticks.) The grep code 2 for errors is not used. If "-f" or "-g" are specified, then 0 is returned if at least one file is found. If no files are found, then 1 is returned. DEBUGGING ACK PROBLEMS If ack gives you output you're not expecting, start with a few simple steps. Try it with --noenv Your environment variables and .ackrc may be doing things you're not expecting, or forgotten you specified. Use --noenv to ignore your environment and .ackrc. Use -f to see what files have been selected for searching Ack's -f was originally added as a debugging tool. If ack is not finding matches you think it should find, run ack -f to see what files have been selected. You can also add the "--show-types" options to show the type of each file selected. Use --dump This lists the ackrc files that are loaded and the options loaded from them. You may be loading an .ackrc file that you didn't know you were loading. ACKRC LOCATION SEMANTICS Ack can load its configuration from many sources. The following list specifies the sources Ack looks for configuration files; each one that is found is loaded in the order specified here, and each one overrides options set in any of the sources preceding it. (For example, if I set --sort-files in my user ackrc, and --nosort-files on the command line, the command line takes precedence) o Defaults are loaded from App::Ack::ConfigDefaults. This can be omitted using "--ignore-ack-defaults". o Global ackrc Options are then loaded from the global ackrc. This is located at "/etc/ackrc" on Unix-like systems. Under Windows XP and earlier, the global ackrc is at "C:\Documents and Settings\All Users\Application Data\ackrc" Under Windows Vista/7, the global ackrc is at "C:\ProgramData\ackrc" The "--noenv" option prevents all ackrc files from being loaded. o User ackrc Options are then loaded from the user's ackrc. This is located at "$HOME/.ackrc" on Unix-like systems. Under Windows XP and earlier, the user's ackrc is at "C:\Documents and Settings\$USER\Application Data\ackrc". Under Windows Vista/7, the user's ackrc is at "C:\Users\$USER\AppData\Roaming\ackrc". If you want to load a different user-level ackrc, it may be specified with the $ACKRC environment variable. The "--noenv" option prevents all ackrc files from being loaded. o Project ackrc Options are then loaded from the project ackrc. The project ackrc is the first ackrc file with the name ".ackrc" or "_ackrc", first searching in the current directory, then the parent directory, then the grandparent directory, etc. This can be omitted using "--noenv". o --ackrc The "--ackrc" option may be included on the command line to specify an ackrc file that can override all others. It is consulted even if "--noenv" is present. o Command line Options are then loaded from the command line. BUGS & ENHANCEMENTS ack is based at GitHub at Please report any bugs or feature requests to the issues list at GitHub: . Please include the operating system that you're using; the output of the command "ack --version"; and any customizations in your .ackrc you may have. To suggest enhancements, please submit an issue at . Also read the DEVELOPERS.md file in the ack code repository. Also, feel free to discuss your issues on the ack mailing list at . SUPPORT Support for and information about ack can be found at: o The ack homepage o Source repository o The ack issues list at GitHub o The ack announcements mailing list o The ack users' mailing list o The ack development mailing list COMMUNITY There are ack mailing lists and a Slack channel for ack. See for details. FAQ This is the Frequently Asked Questions list for ack. Can I stop using grep now? Many people find ack to be better than grep as an everyday tool 99% of the time, but don't throw grep away, because there are times you'll still need it. For example, you might be looking through huge log files and not using regular expressions. In that case, grep will probably perform better. Why isn't ack finding a match in (some file)? First, take a look and see if ack is even looking at the file. ack is intelligent in what files it will search and which ones it won't, but sometimes that can be surprising. Use the "-f" switch, with no regex, to see a list of files that ack will search for you. If your file doesn't show up in the list of files that "ack -f" shows, then ack never looks in it. Wouldn't it be great if ack did search & replace? No, ack will always be read-only. Perl has a perfectly good way to do search & replace in files, using the "-i", "-p" and "-n" switches. You can certainly use ack to select your files to update. For example, to change all "foo" to "bar" in all PHP files, you can do this from the Unix shell: $ perl -i -p -e's/foo/bar/g' $(ack -f --php) Can I make ack recognize .xyz files? Yes! Please see "Defining your own types" in the ack manual. Will you make ack recognize .xyz files by default? We might, depending on how widely-used the file format is. Submit an issue at in the GitHub issue queue at . Explain what the file format is, where we can find out more about it, and what you have been using in your .ackrc to support it. Please do not bother creating a pull request. The code for filetypes is trivial compared to the rest of the process we go through. Why is it called ack if it's called ack-grep? The name of the program is "ack". Some packagers have called it "ack- grep" when creating packages because there's already a package out there called "ack" that has nothing to do with this ack. I suggest you make a symlink named ack that points to ack-grep because one of the crucial benefits of ack is having a name that's so short and simple to type. To do that, run this with sudo or as root: ln -s /usr/bin/ack-grep /usr/bin/ack Alternatively, you could use a shell alias: # bash/zsh alias ack=ack-grep # csh alias ack ack-grep What does ack mean? Nothing. I wanted a name that was easy to type and that you could pronounce as a single syllable. Can I do multi-line regexes? No, ack does not support regexes that match multiple lines. Doing so would require reading in the entire file at a time. If you want to see lines near your match, use the "--A", "--B" and "--C" switches for displaying context. Why is ack telling me I have an invalid option when searching for "+foo"? ack treats command line options beginning with "+" or "-" as options; if you would like to search for these, you may prefix your search term with "--" or use the "--match" option. (However, don't forget that "+" is a regular expression metacharacter!) Why does "ack '.{40000,}'" fail? Isn't that a valid regex? The Perl language limits the repetition quantifier to 32K. You can search for ".{32767}" but not ".{32768}". Ack does "X" and shouldn't, should it? We try to remain as close to grep's behavior as possible, so when in doubt, see what grep does! If there's a mismatch in functionality there, please submit an issue to GitHub, and/or bring it up on the ack- users mailing list. ACKNOWLEDGEMENTS How appropriate to have acknowledgements! Thanks to everyone who has contributed to ack in any way, including Thomas Gossler, Kieran Mace, Volker Glave, Axel Beckert, Eric Pement, Gabor Szabo, Frieder Bluemle, Grzegorz Kaczmarczyk, Dan Book, Tomasz Konojacki, Salomon Smeke, M. Scott Ford, Anders Eriksson, H.Merijn Brand, Duke Leto, Gerhard Poul, Ethan Mallove, Marek Kubica, Ray Donnelly, Nikolaj Schumacher, Ed Avis, Nick Morrott, Austin Chamberlin, Varadinsky, Sebastien Feugere, Jakub Wilk, Pete Houston, Stephen Thirlwall, Jonah Bishop, Chris Rebert, Denis Howe, Raul Gundin, James McCoy, Daniel Perrett, Steven Lee, Jonathan Perret, Fraser Tweedale, Raal Gundan, Steffen Jaeckel, Stephan Hohe, Michael Beijen, Alexandr Ciornii, Christian Walde, Charles Lee, Joe McMahon, John Warwick, David Steinbrunner, Kara Martens, Volodymyr Medvid, Ron Savage, Konrad Borowski, Dale Sedivic, Michael McClimon, Andrew Black, Ralph Bodenner, Shaun Patterson, Ryan Olson, Shlomi Fish, Karen Etheridge, Olivier Mengue, Matthew Wild, Scott Kyle, Nick Hooey, Bo Borgerson, Mark Szymanski, Marq Schneider, Packy Anderson, JR Boyens, Dan Sully, Ryan Niebur, Kent Fredric, Mike Morearty, Ingmar Vanhassel, Eric Van Dewoestine, Sitaram Chamarty, Adam James, Richard Carlsson, Pedro Melo, AJ Schuster, Phil Jackson, Michael Schwern, Jan Dubois, Christopher J. Madsen, Matthew Wickline, David Dyck, Jason Porritt, Jjgod Jiang, Thomas Klausner, Uri Guttman, Peter Lewis, Kevin Riggle, Ori Avtalion, Torsten Blix, Nigel Metheringham, Gabor Szabo, Tod Hagan, Michael Hendricks, AEvar Arnfjordh Bjarmason, Piers Cawley, Stephen Steneker, Elias Lutfallah, Mark Leighton Fisher, Matt Diephouse, Christian Jaeger, Bill Sully, Bill Ricker, David Golden, Nilson Santos F. Jr, Elliot Shank, Merijn Broeren, Uwe Voelker, Rick Scott, Ask Bjorn Hansen, Jerry Gay, Will Coleda, Mike O'Regan, Slaven Rezic, Mark Stosberg, David Alan Pisoni, Adriano Ferreira, James Keenan, Leland Johnson, Ricardo Signes, Pete Krawczyk and Rob Hoelz. AUTHOR Andy Lester, "" COPYRIGHT & LICENSE Copyright 2005-2023 Andy Lester. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License v2.0. See https://www.perlfoundation.org/artistic-license-20.html or the LICENSE.md file that comes with the ack distribution. perl v5.38.0 2023-07-25 ACK(1)