ack
Search files for a pattern
TLDR
Search for files containing a string or regex in the current directory recursively
Search for a case-insensitive pattern
Search for lines matching a pattern, printing only the matched text and not the rest of the line
Limit search to files of a specific type
Do not search in files of a specific type
Count the total number of matches found
Print the file names and the number of matches for each file only
List all the values that can be used with --type
SYNOPSIS
ack [options] <PATTERN> [<FILE> ...]
PARAMETERS
-i, --ignore-case
Ignore case distinctions in PATTERN
-w, --word
Search for PATTERN only as a whole word
-l, --files-with-matches
Only print filenames containing matches
-L, --files-without-matches
Only print filenames not containing matches
--type=TYPE
Operate on files of TYPE (e.g., --type=perl, --type=js)
--ignore-dir=DIR
Ignore directory DIR
-a, --all
Include all text files, even those without explicit type
-c, --count
Count matching lines per file
-f
Read list of files to search from stdin or args
-g PATTERN
Find files matching PATTERN
--color
Colorize matches (on|off|always)
-A NUM, --after-context=NUM
Print NUM lines of trailing context
-B NUM, --before-context=NUM
Print NUM lines of leading context
-C NUM, --context=NUM
Print NUM lines of context before/after
DESCRIPTION
Ack is a powerful, grep-inspired command-line tool designed specifically for searching large codebases and text files. Unlike traditional grep, ack intelligently skips binary files, version control directories (like .git, .svn), and common build directories (e.g., blib, _build) by default, making it faster and more efficient for developers.
It supports Perl-compatible regular expressions (PCRE), colorized output for matches, and file type filtering (e.g., --perl, --js) based on extensions and shebangs. Ack highlights matches in context with line numbers, handles recursion across directories, and provides options for ignoring case, inverting matches, or showing only filenames with hits.
Ideal for programmers, ack reduces noise in search results, speeds up workflows in projects with thousands of files, and integrates well with editors like Vim and Emacs. It's written in Perl, portable across Unix-like systems, and available as 'ack-grep' in some distros to avoid conflicts with BSD ack.
CAVEATS
Ack is not installed by default on most systems; install via package manager (e.g., apt install ack). Some distros rename it to ack-grep. Limited to Perl regex; newer tools like ripgrep may be faster.
FILE TYPES
Ack defines 50+ filetypes like --python, --html. List with ack --help=types; override with --type-set.
EXAMPLES
ack --perl 'TODO' searches TODO in Perl files.
ack -i error . case-insensitive search for 'error' recursively.
ack --print0 | xargs -0 grep foo pipes nul-separated filenames.
HISTORY
Developed by Andy Lester in 2007 as 'ack' ("better grep") to address grep's shortcomings for code searching. Written in Perl, it evolved through versions: ack 1.x (2008-2010), ack 2.x (2010-2014) with improved filetypes, and ack 3.x (2014+) adding --known-types and bug fixes. Widely adopted by developers; maintained on GitHub.


