LinuxCommandLibrary

ack

TLDR

Search for a pattern in current directory recursively

$ ack [pattern]
copy
Search for a pattern in specific file types
$ ack --type=[perl|python|ruby|js] [pattern]
copy
Search with case insensitive matching
$ ack -i [pattern]
copy
List all files that match without showing matches
$ ack -l [pattern]
copy
Show context lines around matches
$ ack -C [3] [pattern]
copy

SYNOPSIS

ack [options] pattern [file|directory...]

DESCRIPTION

ack is a code-searching tool designed as an alternative to grep, optimized for programmers. It automatically skips backup files, version control directories (.git, .svn), and binary files while searching recursively through source code.
The tool provides built-in file type filtering, allowing searches limited to specific programming languages. Output is formatted with color highlighting and file grouping for easier reading. It uses Perl regular expressions, providing powerful pattern matching capabilities.

PARAMETERS

-i, --ignore-case

Case insensitive search
-v, --invert-match
Invert the match; select non-matching lines
-w, --word-regexp
Match whole words only
-l, --files-with-matches
Print only filenames containing matches
-L, --files-without-matches
Print filenames that don't contain matches
-c, --count
Print count of matching lines per file
-C num, --context=num
Print num lines of context around matches
-A num, --after-context=num
Print num lines after each match
-B num, --before-context=num
Print num lines before each match
--type=TYPE
Search only files of TYPE (perl, python, ruby, js, etc.)
--nocolor
Disable color output
-f
Print files that would be searched (dry run)
--ignore-dir=name
Ignore directory name
--help-types
List all recognized file types

CAVEATS

ack is slower than newer tools like ripgrep or ag (The Silver Searcher) on large codebases. It requires Perl to be installed. Some file types may not be recognized by default and require custom configuration in .ackrc.

HISTORY

ack was created by Andy Lester and first released in 2005. It was designed to be a better grep for programmers, addressing common frustrations with searching through codebases. The tool influenced later search tools like ag and ripgrep.

SEE ALSO

grep(1), ag(1), rg(1), git-grep(1)

Copied to clipboard