Ack: Usage Cheat Sheet



Search for PATTERN in each source file in the tree from the current directory on down. If any files or directories are specified, then only those files and directories are checked. ack may also search STDIN, but only if no file or directory arguments are specified, or if one of them is -.

Default switches may be specified in the ACK_OPTIONS environment variable or an .ackrc file. If you want no dependency on the environment, turn it off with --noenv.


ack -i select

Ack: Searching Cheat Sheet

-i, --ignore-caseIgnore case distinctions in pattern
--[no]smart-caseIgnore case distinctions in pattern, but only if pattern contains no upper caseIgnored if -i is specified.
-v, --invert-matchInvert match: select non-matching lines
-w, --word-regexpForce pattern to match only whole words
-Q, --literalQuote all metacharacters: pattern is literal

Ack: File Presentation Cheat Sheet

--pager=COMMANDPipe all ack output through COMMANDFor example, --pager="less -R". Ignored if output is redirected.
--nopagerDo not send output through a pagerCancels any setting in ~/.ackrc, ACK_PAGER or ACK_PAGER_COLOR.
--[no]headingPrint a filename heading above each file’s resultsThe default is on, when used interactively.
--[no]breakPrint a break between results from different filesThe default is on, when used interactively.
--groupSame as --heading --break
--nogroupSame as --noheading --nobreak
--[no]colorHighlight the matching textThe default is on unless output is redirected, or on Windows.
--color-filename=COLORSet color for filenames
--color-match=COLORSet color for matches
--color-lineno=COLORSet color for line numbers
--[no]colourSame as --[no]color
--flushFlush output immediately, even when ack is used non-interactively (when output goes to a pipe or file)

Ack: File Finding Cheat Sheet

-fOnly print the files selected, without searchingThe PATTERN must not be specified.
-gSame as -f, but only select files matching PATTERN
--sort-filesSort the found files lexically
--show-typesShow which types each file has
--files-from=FILERead the list of files to search from FILE
-xRead the list of files to search from STDIN

Ack: Search Output Cheat Sheet

--lines=NUMOnly print NUM lines of each file
-l, --files-with-matchesOnly print filenames containing matches
-L, --files-without-matchesOnly print filenames with no matches
--output=exprOutput the evaluation of expression for each lineTurns off text highlighting.
-oShow only the part of a line matching pattern
--passthruPrint all lines, whether matching or not
--match PATTERNSpecify pattern explicitly.
-m, --max-count=NUMStop searching in each file after NUM matches
-1Stop searching after one match of any kind
-H, --with-filenamePrint the filename for each matchThis is the default unless explicitly searching a single file.
-h, --no-filenameSuppress the prefixing filename on output
-c, --countShow number of lines matching per file
--[no]columnShow the column number of the first match
-A NUM, --after-context=NUMPrint NUM lines of trailing context after matching lines
-B NUM, --before-context=NUMPrint NUM lines of leading context before matching lines
-C [NUM], --context[=NUM]Print NUM lines of output contextThe default is 2.
--print0Print null byte as separator between filenamesOnly works with -f, -g, -l, -L or -c.
-sSuppress error messages about nonexistent or unreadable files

Ack: File Inclusion and Exclusion Cheat Sheet

--[no]ignore-dir=nameAdd or remove directory from the list of ignored directories
--[no]ignore-directory=nameSynonym for --ignore-dir
--ignore-file=filterAdd filter for ignoring files
-r, -R, --recurseRecurse into subdirectoriesThis is ack’s default behavior.
-n, --no-recurseNo descending into subdirectories
--[no]followFollow symlinksDefault is off.
-k, --known-typesInclude only files with types that ack recognizes
--type=XInclude only files with the filetype X
--type=noXExclude files with the filetype XSee ack --help-types for supported filetypes.

Ack: File Type Specification Cheat Sheet

--type-set TYPE:FILTER:FILTERARGSFiles with the given FILTERARGS applied to the given FILTER are recognized as being of type TYPE. This replaces an existing definition for type TYPE
--type-add TYPE:FILTER:FILTERARGSFiles with the given FILTERARGS applied to the given FILTER are recognized as being of type TYPE
--type-del TYPERemove all filters associated with TYPE

Ack: Miscellaneous Cheat Sheet

--[no]envIgnore environment variables and global ackrc files
--ackrc=filenameSpecify an ackrc file to use
--ignore-ack-defaultsIgnore the default definitions that ack includes
--create-ackrcOutputs a default ackrc for your customization to standard output
--help, -?Display help
--help-typesDisplay all known types
--dumpDump information on which options are loaded from which RC files
--[no]filterForce ack to treat standard input as a pipe (--filter) or tty (--nofilter)
--manMan page
--versionDisplay version and copyright
--thppptBill the Cat
--barThe warning admiral

Ack: File Types Cheat Sheet

--[no]lua.lua, first line matches /^#!.*\blua(jit)?/
--[no], first line matches /^#!.*\bperl/
--[no]php.php.phpt.php3.php4.php5.phtml, first line matches /^#!.*\bphp/
--[no], first line matches /^#!.*\bpython/
--[no]ruby.rb.rhtml.rjs.rxml.erb.rake.specRakefile, first line matches /^#!.*\bruby/
--[no], first line matches /^#!.*\b(?:ba|t?c|k|z|fi)?sh\b/
--[no]xml.xml.dtd.xsl.xslt.ent, first line matches /<[?]xml/