1ACK(1) User Contributed Perl Documentation ACK(1)
2
3
4
6 ack - grep-like text finder
7
9 ack [options] PATTERN [FILE...]
10 ack -f [options] [DIRECTORY...]
11
13 ack is designed as an alternative to grep for programmers.
14
15 ack searches the named input FILEs or DIRECTORYs for lines containing a
16 match to the given PATTERN. By default, ack prints the matching lines.
17 If no FILE or DIRECTORY is given, the current directory will be
18 searched.
19
20 PATTERN is a Perl regular expression. Perl regular expressions are
21 commonly found in other programming languages, but for the particulars
22 of their behavior, please consult perlreref
23 <https://perldoc.perl.org/perlreref.html>. If you don't know how to
24 use regular expression but are interested in learning, you may consult
25 perlretut <https://perldoc.perl.org/perlretut.html>. If you do not
26 need or want ack to use regular expressions, please see the
27 "-Q"/"--literal" option.
28
29 Ack can also list files that would be searched, without actually
30 searching them, to let you take advantage of ack's file-type filtering
31 capabilities.
32
34 If files are not specified for searching, either on the command line or
35 piped in with the "-x" option, ack delves into subdirectories selecting
36 files for searching.
37
38 ack is intelligent about the files it searches. It knows about certain
39 file types, based on both the extension on the file and, in some cases,
40 the contents of the file. These selections can be made with the --type
41 option.
42
43 With no file selection, ack searches through regular files that are not
44 explicitly excluded by --ignore-dir and --ignore-file options, either
45 present in ackrc files or on the command line.
46
47 The default options for ack ignore certain files and directories.
48 These include:
49
50 • Backup files: Files matching #*# or ending with ~.
51
52 • Coredumps: Files matching core.\d+
53
54 • Version control directories like .svn and .git.
55
56 Run ack with the "--dump" option to see what settings are set.
57
58 However, ack always searches the files given on the command line, no
59 matter what type. If you tell ack to search in a coredump, it will
60 search in a coredump.
61
63 ack descends through the directory tree of the starting directories
64 specified. If no directories are specified, the current working
65 directory is used. However, it will ignore the shadow directories used
66 by many version control systems, and the build directories used by the
67 Perl MakeMaker system. You may add or remove a directory from this
68 list with the --[no]ignore-dir option. The option may be repeated to
69 add/remove multiple directories from the ignore list.
70
71 For a complete list of directories that do not get searched, run "ack
72 --dump".
73
75 The "--range-start" and "--range-end" options let you specify ranges of
76 lines to search within each file.
77
78 Say you had the following file, called testfile:
79
80 # This function calls print on "foo".
81 sub foo {
82 print 'foo';
83 }
84 my $print = 1;
85 sub bar {
86 print 'bar';
87 }
88 my $task = 'print';
89
90 Calling "ack print" will give us five matches:
91
92 $ ack print testfile
93 # This function calls print on "foo".
94 print 'foo';
95 my $print = 1;
96 print 'bar';
97 my $task = 'print';
98
99 What if we only want to search for "print" within the subroutines? We
100 can specify ranges of lines that we want ack to search. The range
101 starts with any line that matches the pattern "^sub \w+", and stops
102 with any line that matches "^}".
103
104 $ ack --range-start='^sub \w+' --range-end='^}' print testfile
105 print 'foo';
106 print 'bar';
107
108 Note that ack searched two ranges of lines. The listing below shows
109 which lines were in a range and which were out of the range.
110
111 Out # This function calls print on "foo".
112 In sub foo {
113 In print 'foo';
114 In }
115 Out my $print = 1;
116 In sub bar {
117 In print 'bar';
118 In }
119 Out my $task = 'print';
120
121 You don't have to specify both "--range-start" and "--range-end". IF
122 "--range-start" is omitted, then the range runs from the first line in
123 the file until the first line that matches "--range-end". Similarly,
124 if "--range-end" is omitted, the range runs from the first line
125 matching "--range-start" to the end of the file.
126
127 For example, if you wanted to search all HTML files up until the first
128 instance of the "<body>", you could do
129
130 ack foo --html --range-end='<body>'
131
132 Or to search after Perl's `__DATA__` or `__END__` markers, you would do
133
134 ack pattern --perl --range-start='^__(END|DATA)__'
135
136 It's possible for a range to start and stop on the same line. For
137 example
138
139 --range-start='<title>' --range-end='</title>'
140
141 would match this line as both the start and end of the range, making a
142 one-line range.
143
144 <title>Page title</title>
145
146 Note that the patterns in "--range-start" and "--range-end" are not
147 affected by options like "-i", "-w" and "-Q" that modify the behavior
148 of the main pattern being matched.
149
150 Again, ranges only affect where matches are looked for. Everything
151 else in ack works the same way. Using "-c" option with a range will
152 give a count of all the matches that appear within those ranges. The
153 "-l" shows those files that have a match within a range, and the "-L"
154 option shows files that do not have a match within a range.
155
156 The "-v" option for negating a match works inside the range, too. To
157 see lines that don't match "google" within the "<head>" section of your
158 HTML files, you could do:
159
160 ack google -v --html --range-start='<head' --range-end='</head>'
161
162 Specifying a range to search does not affect how matches are displayed.
163 The context for a match will still be the same, and
164
165 Using the context options work the same way, and will show context
166 lines for matches even if the context lines fall outside the range.
167 Similarly, "--passthru" will show all lines in the file, but only show
168 matches for lines within the range.
169
171 --ackrc
172 Specifies an ackrc file to load after all others; see "ACKRC
173 LOCATION SEMANTICS".
174
175 -A NUM, --after-context=NUM
176 Print NUM lines of trailing context after matching lines.
177
178 -B NUM, --before-context=NUM
179 Print NUM lines of leading context before matching lines.
180
181 --[no]break
182 Print a break between results from different files. On by default
183 when used interactively.
184
185 -C [NUM], --context[=NUM]
186 Print NUM lines (default 2) of context around matching lines. You
187 can specify zero lines of context to override another context
188 specified in an ackrc.
189
190 -c, --count
191 Suppress normal output; instead print a count of matching lines for
192 each input file. If -l is in effect, it will only show the number
193 of lines for each file that has lines matching. Without -l, some
194 line counts may be zeroes.
195
196 If combined with -h (--no-filename) ack outputs only one total
197 count.
198
199 --[no]color, --[no]colour
200 --color highlights the matching text. --nocolor suppresses the
201 color. This is on by default unless the output is redirected.
202
203 On Windows, this option is off by default unless the
204 Win32::Console::ANSI module is installed or the "ACK_PAGER_COLOR"
205 environment variable is used.
206
207 --color-filename=color
208 Sets the color to be used for filenames.
209
210 --color-match=color
211 Sets the color to be used for matches.
212
213 --color-colno=color
214 Sets the color to be used for column numbers.
215
216 --color-lineno=color
217 Sets the color to be used for line numbers.
218
219 --[no]column
220 Show the column number of the first match. This is helpful for
221 editors that can place your cursor at a given position.
222
223 --create-ackrc
224 Dumps the default ack options to standard output. This is useful
225 for when you want to customize the defaults.
226
227 --dump
228 Writes the list of options loaded and where they came from to
229 standard output. Handy for debugging.
230
231 --[no]env
232 --noenv disables all environment processing. No .ackrc is read and
233 all environment variables are ignored. By default, ack considers
234 .ackrc and settings in the environment.
235
236 --flush
237 --flush flushes output immediately. This is off by default unless
238 ack is running interactively (when output goes to a pipe or file).
239
240 -f Only print the files that would be searched, without actually doing
241 any searching. PATTERN must not be specified, or it will be taken
242 as a path to search.
243
244 --files-from=FILE
245 The list of files to be searched is specified in FILE. The list of
246 files are separated by newlines. If FILE is "-", the list is
247 loaded from standard input.
248
249 Note that the list of files is not filtered in any way. If you add
250 "--type=html" in addition to "--files-from", the "--type" will be
251 ignored.
252
253 --[no]filter
254 Forces ack to act as if it were receiving input via a pipe.
255
256 --[no]follow
257 Follow or don't follow symlinks, other than whatever starting files
258 or directories were specified on the command line.
259
260 This is off by default.
261
262 -g PATTERN
263 Print searchable files where the relative path + filename matches
264 PATTERN.
265
266 Note that
267
268 ack -g foo
269
270 is exactly the same as
271
272 ack -f | ack foo
273
274 This means that just as ack will not search, for example, .jpg
275 files, "-g" will not list .jpg files either. ack is not intended
276 to be a general-purpose file finder.
277
278 Note also that if you have "-i" in your .ackrc that the filenames
279 to be matched will be case-insensitive as well.
280
281 This option can be combined with --color to make it easier to spot
282 the match.
283
284 --[no]group
285 --group groups matches by file name. This is the default when used
286 interactively.
287
288 --nogroup prints one result per line, like grep. This is the
289 default when output is redirected.
290
291 -H, --with-filename
292 Print the filename for each match. This is the default unless
293 searching a single explicitly specified file.
294
295 -h, --no-filename
296 Suppress the prefixing of filenames on output when multiple files
297 are searched.
298
299 --[no]heading
300 Print a filename heading above each file's results. This is the
301 default when used interactively.
302
303 --help
304 Print a short help statement.
305
306 --help-types
307 Print all known types.
308
309 --help-colors
310 Print a chart of various color combinations.
311
312 --help-rgb-colors
313 Like --help-colors but with more precise RGB colors.
314
315 -i, --ignore-case
316 Ignore case distinctions in PATTERN. Overrides --smart-case and
317 -I.
318
319 -I, --no-ignore-case
320 Turns on case distinctions in PATTERN. Overrides --smart-case and
321 -i.
322
323 --ignore-ack-defaults
324 Tells ack to completely ignore the default definitions provided
325 with ack. This is useful in combination with --create-ackrc if you
326 really want to customize ack.
327
328 --[no]ignore-dir=DIRNAME, --[no]ignore-directory=DIRNAME
329 Ignore directory (as CVS, .svn, etc are ignored). May be used
330 multiple times to ignore multiple directories. For example, mason
331 users may wish to include --ignore-dir=data. The --noignore-dir
332 option allows users to search directories which would normally be
333 ignored (perhaps to research the contents of .svn/props
334 directories).
335
336 The DIRNAME must always be a simple directory name. Nested
337 directories like foo/bar are NOT supported. You would need to
338 specify --ignore-dir=foo and then no files from any foo directory
339 are taken into account by ack unless given explicitly on the
340 command line.
341
342 --ignore-file=FILTER:ARGS
343 Ignore files matching FILTER:ARGS. The filters are specified
344 identically to file type filters as seen in "Defining your own
345 types".
346
347 -k, --known-types
348 Limit selected files to those with types that ack knows about.
349
350 -l, --files-with-matches
351 Only print the filenames of matching files, instead of the matching
352 text.
353
354 -L, --files-without-matches
355 Only print the filenames of files that do NOT match.
356
357 --match PATTERN
358 Specify the PATTERN explicitly. This is helpful if you don't want
359 to put the regex as your first argument, e.g. when executing
360 multiple searches over the same set of files.
361
362 # search for foo and bar in given files
363 ack file1 t/file* --match foo
364 ack file1 t/file* --match bar
365
366 -m=NUM, --max-count=NUM
367 Print only NUM matches out of each file. If you want to stop ack
368 after printing the first match of any kind, use the -1 options.
369
370 --man
371 Print this manual page.
372
373 -n, --no-recurse
374 No descending into subdirectories.
375
376 --not=PATTERN
377 Specifies a PATTERN that must NOT me true on a given line for a
378 match to occur. This option can be repeated.
379
380 If you want to find all the lines with "dogs" but not if "cats" or
381 "fish" appear on the line, use:
382
383 ack dogs --not cats --not fish
384
385 Note that the options that affect "dogs" also affect "cats" and
386 "fish", so if you have
387
388 ack -i -w dogs --not cats
389
390 the the search for both "dogs" and "cats" will be case-insensitive
391 and be word-limited.
392
393 -o Show only the part of each line matching PATTERN (turns off text
394 highlighting). This is exactly the same as "--output=$&".
395
396 --output=expr
397 Output the evaluation of expr for each line (turns off text
398 highlighting). If PATTERN matches more than once then a line is
399 output for each non-overlapping match.
400
401 expr may contain the strings "\n", "\r" and "\t", which will be
402 expanded to their corresponding characters line feed, carriage
403 return and tab, respectively.
404
405 expr may also contain the following Perl special variables:
406
407 $1 through $9
408 The subpattern from the corresponding set of capturing
409 parentheses. If your pattern is "(.+) and (.+)", and the
410 string is "this and that', then $1 is "this" and $2 is "that".
411
412 $_ The contents of the line in the file.
413
414 $. The number of the line in the file.
415
416 $&, "$`" and "$'"
417 $& is the the string matched by the pattern, "$`" is what
418 precedes the match, and "$'" is what follows it. If the
419 pattern is gra(ph|nd) and the string is "lexicographic", then
420 $& is "graph", "$`" is "lexico" and "$'" is "ic".
421
422 Use of these variables in your output will slow down the
423 pattern matching.
424
425 $+ The match made by the last parentheses that matched in the
426 pattern. For example, if your pattern is "Version:
427 (.+)|Revision: (.+)", then $+ will contain whichever set of
428 parentheses matched.
429
430 $f $f is available, in "--output" only, to insert the filename.
431 This is a stand-in for the discovered $filename usage in old
432 "ack2 --output", which is disallowed with "ack3" improved
433 security.
434
435 The intended usage is to provide the grep or compile-error
436 syntax needed for editor/IDE go-to-line integration, e.g.
437 "--output=$f:$.:$_" or "--output=$f\t$.\t$&"
438
439 --pager=program, --nopager
440 --pager directs ack's output through program. This can also be
441 specified via the "ACK_PAGER" and "ACK_PAGER_COLOR" environment
442 variables.
443
444 Using --pager does not suppress grouping and coloring like piping
445 output on the command-line does.
446
447 --nopager cancels any setting in ~/.ackrc, "ACK_PAGER" or
448 "ACK_PAGER_COLOR". No output will be sent through a pager.
449
450 --passthru
451 Prints all lines, whether or not they match the expression.
452 Highlighting will still work, though, so it can be used to
453 highlight matches while still seeing the entire file, as in:
454
455 # Watch a log file, and highlight a certain IP address.
456 $ tail -f ~/access.log | ack --passthru 123.45.67.89
457
458 --print0
459 Only works in conjunction with -f, -g, -l or -c, options that only
460 list filenames. The filenames are output separated with a null
461 byte instead of the usual newline. This is helpful when dealing
462 with filenames that contain whitespace, e.g.
463
464 # Remove all files of type HTML.
465 ack -f --html --print0 | xargs -0 rm -f
466
467 -p[N], --proximate[=N]
468 Groups together match lines that are within N lines of each other.
469 This is useful for visually picking out matches that appear close
470 to other matches.
471
472 For example, if you got these results without the "--proximate"
473 option,
474
475 15: First match
476 18: Second match
477 19: Third match
478 37: Fourth match
479
480 they would look like this with "--proximate=1"
481
482 15: First match
483
484 18: Second match
485 19: Third match
486
487 37: Fourth match
488
489 and this with "--proximate=3".
490
491 15: First match
492 18: Second match
493 19: Third match
494
495 37: Fourth match
496
497 If N is omitted, N is set to 1.
498
499 -P Negates the effect of the --proximate option. Shortcut for
500 --proximate=0.
501
502 -Q, --literal
503 Quote all metacharacters in PATTERN, it is treated as a literal.
504
505 -r, -R, --recurse
506 Recurse into sub-directories. This is the default and just here for
507 compatibility with grep. You can also use it for turning
508 --no-recurse off.
509
510 --range-start=PATTERN, --range-end=PATTERN
511 Specifies patterns that mark the start and end of a range. See
512 "MATCHING IN A RANGE OF LINES" for details.
513
514 -s Suppress error messages about nonexistent or unreadable files.
515 This is taken from fgrep.
516
517 -S, --[no]smart-case, --no-smart-case
518 Ignore case in the search strings if PATTERN contains no uppercase
519 characters. This is similar to "smartcase" in the vim text editor.
520 The options overrides -i and -I.
521
522 -S is a synonym for --smart-case.
523
524 -i always overrides this option.
525
526 --sort-files
527 Sorts the found files lexicographically. Use this if you want your
528 file listings to be deterministic between runs of ack.
529
530 --show-types
531 Outputs the filetypes that ack associates with each file.
532
533 Works with -f and -g options.
534
535 -t TYPE, --type=TYPE, --TYPE
536 Specify the types of files to include in the search. TYPE is a
537 filetype, like perl or xml. --type=perl can also be specified as
538 --perl, although this is deprecated.
539
540 Type inclusions can be repeated and are ORed together.
541
542 See ack --help-types for a list of valid types.
543
544 -T TYPE, --type=noTYPE, --noTYPE
545 Specifies the type of files to exclude from the search.
546 --type=noperl can be done as --noperl, although this is deprecated.
547
548 If a file is of both type "foo" and "bar", specifying both
549 --type=foo and --type=nobar will exclude the file, because an
550 exclusion takes precedence over an inclusion.
551
552 --type-add TYPE:FILTER:ARGS
553 Files with the given ARGS applied to the given FILTER are
554 recognized as being of (the existing) type TYPE. See also
555 "Defining your own types".
556
557 --type-set TYPE:FILTER:ARGS
558 Files with the given ARGS applied to the given FILTER are
559 recognized as being of type TYPE. This replaces an existing
560 definition for type TYPE. See also "Defining your own types".
561
562 --type-del TYPE
563 The filters associated with TYPE are removed from Ack, and are no
564 longer considered for searches.
565
566 --[no]underline
567 Turns on underlining of matches, where "underlining" is printing a
568 line of carets under the match.
569
570 $ ack -u foo
571 peanuts.txt
572 17: Come kick the football you fool
573 ^^^ ^^^
574 623: Price per square foot
575 ^^^
576
577 This is useful if you're dumping the results of an ack run into a
578 text file or printer that doesn't support ANSI color codes.
579
580 The setting of underline does not affect highlighting of matches.
581
582 -v, --invert-match
583 Invert match: select non-matching lines.
584
585 --version
586 Display version and copyright information.
587
588 -w, --word-regexp
589 Force PATTERN to match only whole words.
590
591 -x An abbreviation for --files-from=-. The list of files to search are
592 read from standard input, with one line per file.
593
594 Note that the list of files is not filtered in any way. If you add
595 "--type=html" in addition to "-x", the "--type" will be ignored.
596
597 -1 Stops after reporting first match of any kind. This is different
598 from --max-count=1 or -m1, where only one match per file is shown.
599 Also, -1 works with -f and -g, where -m does not.
600
601 --thpppt
602 Display the all-important Bill The Cat logo. Note that the exact
603 spelling of --thpppppt is not important. It's checked against a
604 regular expression.
605
606 --bar
607 Check with the admiral for traps.
608
609 --cathy
610 Chocolate, Chocolate, Chocolate!
611
613 The .ackrc file contains command-line options that are prepended to the
614 command line before processing. Multiple options may live on multiple
615 lines. Lines beginning with a # are ignored. A .ackrc might look like
616 this:
617
618 # Always sort the files
619 --sort-files
620
621 # Always color, even if piping to another program
622 --color
623
624 # Use "less -r" as my pager
625 --pager=less -r
626
627 Note that arguments with spaces in them do not need to be quoted, as
628 they are not interpreted by the shell. Basically, each line in the
629 .ackrc file is interpreted as one element of @ARGV.
630
631 ack looks in several locations for .ackrc files; the searching process
632 is detailed in "ACKRC LOCATION SEMANTICS". These files are not
633 considered if --noenv is specified on the command line.
634
636 ack allows you to define your own types in addition to the predefined
637 types. This is done with command line options that are best put into an
638 .ackrc file - then you do not have to define your types over and over
639 again. In the following examples the options will always be shown on
640 one command line so that they can be easily copy & pasted.
641
642 File types can be specified both with the the --type=xxx option, or the
643 file type as an option itself. For example, if you create a filetype
644 of "cobol", you can specify --type=cobol or simply --cobol. File types
645 must be at least two characters long. This is why the C language is
646 --cc and the R language is --rr.
647
648 ack --perl foo searches for foo in all perl files. ack --help-types
649 tells you, that perl files are files ending in .pl, .pm, .pod or .t. So
650 what if you would like to include .xs files as well when searching for
651 --perl files? ack --type-add perl:ext:xs --perl foo does this for you.
652 --type-add appends additional extensions to an existing type.
653
654 If you want to define a new type, or completely redefine an existing
655 type, then use --type-set. ack --type-set eiffel:ext:e,eiffel defines
656 the type eiffel to include files with the extensions .e or .eiffel. So
657 to search for all eiffel files containing the word Bertrand use ack
658 --type-set eiffel:ext:e,eiffel --eiffel Bertrand. As usual, you can
659 also write --type=eiffel instead of --eiffel. Negation also works, so
660 --noeiffel excludes all eiffel files from a search. Redefining also
661 works: ack --type-set cc:ext:c,h and .xs files no longer belong to the
662 type cc.
663
664 When defining your own types in the .ackrc file you have to use the
665 following:
666
667 --type-set=eiffel:ext:e,eiffel
668
669 or writing on separate lines
670
671 --type-set
672 eiffel:ext:e,eiffel
673
674 The following does NOT work in the .ackrc file:
675
676 --type-set eiffel:ext:e,eiffel
677
678 In order to see all currently defined types, use --help-types, e.g.
679 ack --type-set backup:ext:bak --type-add perl:ext:perl --help-types
680
681 In addition to filtering based on extension, ack offers additional
682 filter types. The generic syntax is --type-set TYPE:FILTER:ARGS; ARGS
683 depends on the value of FILTER.
684
685 is:FILENAME
686 is filters match the target filename exactly. It takes exactly one
687 argument, which is the name of the file to match.
688
689 Example:
690
691 --type-set make:is:Makefile
692
693 ext:EXTENSION[,EXTENSION2[,...]]
694 ext filters match the extension of the target file against a list
695 of extensions. No leading dot is needed for the extensions.
696
697 Example:
698
699 --type-set perl:ext:pl,pm,t
700
701 match:PATTERN
702 match filters match the target filename against a regular
703 expression. The regular expression is made case-insensitive for
704 the search.
705
706 Example:
707
708 --type-set make:match:/(gnu)?makefile/
709
710 firstlinematch:PATTERN
711 firstlinematch matches the first line of the target file against a
712 regular expression. Like match, the regular expression is made
713 case insensitive.
714
715 Example:
716
717 --type-add perl:firstlinematch:/perl/
718
720 ack allows customization of the colors it uses when presenting matches
721 onscreen. It uses the colors available in Perl's Term::ANSIColor
722 module, which provides the following listed values. Note that case does
723 not matter when using these values.
724
725 There are four different colors ack uses:
726
727 Aspect Option Env. variable Default
728 -------- ----------------- ------------------ ---------------
729 filename --color-filename ACK_COLOR_FILENAME black on_yellow
730 match --color-match ACK_COLOR_MATCH bold green
731 line no. --color-lineno ACK_COLOR_LINENO bold yellow
732 column no. --color-colno ACK_COLOR_COLNO bold yellow
733
734 The column number column is only used if the column number is shown
735 because of the --column option.
736
737 Colors may be specified by command-line option, such as "ack
738 --color-filename='red on_white'", or by setting an environment
739 variable, such as "ACK_COLOR_FILENAME='red on_white'". Options for
740 colors can be set in your ACKRC file (See "THE .ackrc FILE").
741
742 ack can understand the following colors for the foreground:
743
744 black red green yellow blue magenta cyan white
745
746 The optional background color is specified by prepending "on_" to one
747 of the foreground colors:
748
749 on_black on_red on_green on_yellow on_blue on_magenta on_cyan on_white
750
751 Each of the foreground colors can be modified with the following
752 attributes, which may or may not be supported by your terminal:
753
754 bold faint italic underline blink reverse concealed
755
756 Any combinations of modifiers can be added to the foreground color. If
757 your terminal supports it, and you enjoy visual punishment, you can
758 specify:
759
760 ack --color-filename="blink italic underline bold red on_yellow"
761
762 For charts of the colors and what they look like, run "ack
763 --help-colors" and "ack --help-rgb-colors".
764
765 If the eight standard colors, in their bold, faint and unmodified
766 states, aren't enough for you to choose from, you can also specify
767 colors by their RGB values. They are specified as "rgbXYZ" where X, Y,
768 and Z are values between 0 and 5 giving the intensity of red, green and
769 blue, respectively. Therefore, "rgb500" is pure red, "rgb505" is
770 purple, and so on.
771
772 Background colors can be specified with the "on_" prefix prepended on
773 an RGB color, so that "on_rgb505" would be a purple background.
774
775 The modifier attributes of blink, italic, underscore and so on may or
776 may not work on the RGB colors.
777
778 For a chart of the 216 possible RGB colors, run "ack
779 --help-rgb-colors".
780
782 For commonly-used ack options, environment variables can make life much
783 easier. These variables are ignored if --noenv is specified on the
784 command line.
785
786 ACKRC
787 Specifies the location of the user's .ackrc file. If this file
788 doesn't exist, ack looks in the default location.
789
790 ACK_COLOR_COLNO
791 Color specification for the column number in ack's output. By
792 default, the column number is not shown. You have to enable it
793 with the --column option. See the section "ack Colors" above.
794
795 ACK_COLOR_FILENAME
796 Color specification for the filename in ack's output. See the
797 section "ack Colors" above.
798
799 ACK_COLOR_LINENO
800 Color specification for the line number in ack's output. See the
801 section "ack Colors" above.
802
803 ACK_COLOR_MATCH
804 Color specification for the matched text in ack's output. See the
805 section "ack Colors" above.
806
807 ACK_PAGER
808 Specifies a pager program, such as "more", "less" or "most", to
809 which ack will send its output.
810
811 Using "ACK_PAGER" does not suppress grouping and coloring like
812 piping output on the command-line does, except that on Windows ack
813 will assume that "ACK_PAGER" does not support color.
814
815 "ACK_PAGER_COLOR" overrides "ACK_PAGER" if both are specified.
816
817 ACK_PAGER_COLOR
818 Specifies a pager program that understands ANSI color sequences.
819 Using "ACK_PAGER_COLOR" does not suppress grouping and coloring
820 like piping output on the command-line does.
821
822 If you are not on Windows, you never need to use "ACK_PAGER_COLOR".
823
825 Simple vim integration
826 ack integrates easily with the Vim text editor. Set this in your .vimrc
827 to use ack instead of grep:
828
829 set grepprg=ack\ -k
830
831 That example uses "-k" to search through only files of the types ack
832 knows about, but you may use other default flags. Now you can search
833 with ack and easily step through the results in Vim:
834
835 :grep Dumper perllib
836
837 Editor integration
838 Many users have integrated ack into their preferred text editors. For
839 details and links, see <https://beyondgrep.com/more-tools/>.
840
841 Shell and Return Code
842 For greater compatibility with grep, ack in normal use returns shell
843 return or exit code of 0 only if something is found and 1 if no match
844 is found.
845
846 (Shell exit code 1 is "$?=256" in perl with "system" or backticks.)
847
848 The grep code 2 for errors is not used.
849
850 If "-f" or "-g" are specified, then 0 is returned if at least one file
851 is found. If no files are found, then 1 is returned.
852
854 If ack gives you output you're not expecting, start with a few simple
855 steps.
856
857 Try it with --noenv
858 Your environment variables and .ackrc may be doing things you're not
859 expecting, or forgotten you specified. Use --noenv to ignore your
860 environment and .ackrc.
861
862 Use -f to see what files have been selected for searching
863 Ack's -f was originally added as a debugging tool. If ack is not
864 finding matches you think it should find, run ack -f to see what files
865 have been selected. You can also add the "--show-types" options to
866 show the type of each file selected.
867
868 Use --dump
869 This lists the ackrc files that are loaded and the options loaded from
870 them. You may be loading an .ackrc file that you didn't know you were
871 loading.
872
874 Ack can load its configuration from many sources. The following list
875 specifies the sources Ack looks for configuration files; each one that
876 is found is loaded in the order specified here, and each one overrides
877 options set in any of the sources preceding it. (For example, if I set
878 --sort-files in my user ackrc, and --nosort-files on the command line,
879 the command line takes precedence)
880
881 • Defaults are loaded from App::Ack::ConfigDefaults. This can be
882 omitted using "--ignore-ack-defaults".
883
884 • Global ackrc
885
886 Options are then loaded from the global ackrc. This is located at
887 "/etc/ackrc" on Unix-like systems.
888
889 Under Windows XP and earlier, the global ackrc is at "C:\Documents
890 and Settings\All Users\Application Data\ackrc"
891
892 Under Windows Vista/7, the global ackrc is at
893 "C:\ProgramData\ackrc"
894
895 The "--noenv" option prevents all ackrc files from being loaded.
896
897 • User ackrc
898
899 Options are then loaded from the user's ackrc. This is located at
900 "$HOME/.ackrc" on Unix-like systems.
901
902 Under Windows XP and earlier, the user's ackrc is at "C:\Documents
903 and Settings\$USER\Application Data\ackrc".
904
905 Under Windows Vista/7, the user's ackrc is at
906 "C:\Users\$USER\AppData\Roaming\ackrc".
907
908 If you want to load a different user-level ackrc, it may be
909 specified with the $ACKRC environment variable.
910
911 The "--noenv" option prevents all ackrc files from being loaded.
912
913 • Project ackrc
914
915 Options are then loaded from the project ackrc. The project ackrc
916 is the first ackrc file with the name ".ackrc" or "_ackrc", first
917 searching in the current directory, then the parent directory, then
918 the grandparent directory, etc. This can be omitted using
919 "--noenv".
920
921 • --ackrc
922
923 The "--ackrc" option may be included on the command line to specify
924 an ackrc file that can override all others. It is consulted even
925 if "--noenv" is present.
926
927 • Command line
928
929 Options are then loaded from the command line.
930
932 ack is based at GitHub at <https://github.com/beyondgrep/ack3>
933
934 Please report any bugs or feature requests to the issues list at
935 GitHub: <https://github.com/beyondgrep/ack3/issues>.
936
937 Please include the operating system that you're using; the output of
938 the command "ack --version"; and any customizations in your .ackrc you
939 may have.
940
941 To suggest enhancements, please submit an issue at
942 <https://github.com/beyondgrep/ack3/issues>. Also read the
943 DEVELOPERS.md file in the ack code repository.
944
945 Also, feel free to discuss your issues on the ack mailing list at
946 <https://groups.google.com/group/ack-users>.
947
949 Support for and information about ack can be found at:
950
951 • The ack homepage
952
953 <https://beyondgrep.com/>
954
955 • Source repository
956
957 <https://github.com/beyondgrep/ack3>
958
959 • The ack issues list at GitHub
960
961 <https://github.com/beyondgrep/ack3/issues>
962
963 • The ack announcements mailing list
964
965 <https://groups.google.com/group/ack-announcement>
966
967 • The ack users' mailing list
968
969 <https://groups.google.com/group/ack-users>
970
971 • The ack development mailing list
972
973 <https://groups.google.com/group/ack-users>
974
976 There are ack mailing lists and a Slack channel for ack. See
977 <https://beyondgrep.com/community/> for details.
978
980 This is the Frequently Asked Questions list for ack.
981
982 Can I stop using grep now?
983 Many people find ack to be better than grep as an everyday tool 99% of
984 the time, but don't throw grep away, because there are times you'll
985 still need it. For example, you might be looking through huge log
986 files and not using regular expressions. In that case, grep will
987 probably perform better.
988
989 Why isn't ack finding a match in (some file)?
990 First, take a look and see if ack is even looking at the file. ack is
991 intelligent in what files it will search and which ones it won't, but
992 sometimes that can be surprising.
993
994 Use the "-f" switch, with no regex, to see a list of files that ack
995 will search for you. If your file doesn't show up in the list of files
996 that "ack -f" shows, then ack never looks in it.
997
998 Wouldn't it be great if ack did search & replace?
999 No, ack will always be read-only. Perl has a perfectly good way to do
1000 search & replace in files, using the "-i", "-p" and "-n" switches.
1001
1002 You can certainly use ack to select your files to update. For example,
1003 to change all "foo" to "bar" in all PHP files, you can do this from the
1004 Unix shell:
1005
1006 $ perl -i -p -e's/foo/bar/g' $(ack -f --php)
1007
1008 Can I make ack recognize .xyz files?
1009 Yes! Please see "Defining your own types" in the ack manual.
1010
1011 Will you make ack recognize .xyz files by default?
1012 We might, depending on how widely-used the file format is.
1013
1014 Submit an issue at in the GitHub issue queue at
1015 <https://github.com/beyondgrep/ack3/issues>. Explain what the file
1016 format is, where we can find out more about it, and what you have been
1017 using in your .ackrc to support it.
1018
1019 Please do not bother creating a pull request. The code for filetypes
1020 is trivial compared to the rest of the process we go through.
1021
1022 Why is it called ack if it's called ack-grep?
1023 The name of the program is "ack". Some packagers have called it "ack-
1024 grep" when creating packages because there's already a package out
1025 there called "ack" that has nothing to do with this ack.
1026
1027 I suggest you make a symlink named ack that points to ack-grep because
1028 one of the crucial benefits of ack is having a name that's so short and
1029 simple to type.
1030
1031 To do that, run this with sudo or as root:
1032
1033 ln -s /usr/bin/ack-grep /usr/bin/ack
1034
1035 Alternatively, you could use a shell alias:
1036
1037 # bash/zsh
1038 alias ack=ack-grep
1039
1040 # csh
1041 alias ack ack-grep
1042
1043 What does ack mean?
1044 Nothing. I wanted a name that was easy to type and that you could
1045 pronounce as a single syllable.
1046
1047 Can I do multi-line regexes?
1048 No, ack does not support regexes that match multiple lines. Doing so
1049 would require reading in the entire file at a time.
1050
1051 If you want to see lines near your match, use the "--A", "--B" and
1052 "--C" switches for displaying context.
1053
1054 Why is ack telling me I have an invalid option when searching for "+foo"?
1055 ack treats command line options beginning with "+" or "-" as options;
1056 if you would like to search for these, you may prefix your search term
1057 with "--" or use the "--match" option. (However, don't forget that "+"
1058 is a regular expression metacharacter!)
1059
1060 Why does "ack '.{40000,}'" fail? Isn't that a valid regex?
1061 The Perl language limits the repetition quantifier to 32K. You can
1062 search for ".{32767}" but not ".{32768}".
1063
1064 Ack does "X" and shouldn't, should it?
1065 We try to remain as close to grep's behavior as possible, so when in
1066 doubt, see what grep does! If there's a mismatch in functionality
1067 there, please submit an issue to GitHub, and/or bring it up on the ack-
1068 users mailing list.
1069
1071 How appropriate to have acknowledgements!
1072
1073 Thanks to everyone who has contributed to ack in any way, including
1074 Thomas Gossler, Kieran Mace, Volker Glave, Axel Beckert, Eric Pement,
1075 Gabor Szabo, Frieder Bluemle, Grzegorz Kaczmarczyk, Dan Book, Tomasz
1076 Konojacki, Salomon Smeke, M. Scott Ford, Anders Eriksson, H.Merijn
1077 Brand, Duke Leto, Gerhard Poul, Ethan Mallove, Marek Kubica, Ray
1078 Donnelly, Nikolaj Schumacher, Ed Avis, Nick Morrott, Austin Chamberlin,
1079 Varadinsky, Sébastien Feugère, Jakub Wilk, Pete Houston, Stephen
1080 Thirlwall, Jonah Bishop, Chris Rebert, Denis Howe, Raúl Gundín, James
1081 McCoy, Daniel Perrett, Steven Lee, Jonathan Perret, Fraser Tweedale,
1082 Raál Gundán, Steffen Jaeckel, Stephan Hohe, Michael Beijen, Alexandr
1083 Ciornii, Christian Walde, Charles Lee, Joe McMahon, John Warwick, David
1084 Steinbrunner, Kara Martens, Volodymyr Medvid, Ron Savage, Konrad
1085 Borowski, Dale Sedivic, Michael McClimon, Andrew Black, Ralph Bodenner,
1086 Shaun Patterson, Ryan Olson, Shlomi Fish, Karen Etheridge, Olivier
1087 Mengue, Matthew Wild, Scott Kyle, Nick Hooey, Bo Borgerson, Mark
1088 Szymanski, Marq Schneider, Packy Anderson, JR Boyens, Dan Sully, Ryan
1089 Niebur, Kent Fredric, Mike Morearty, Ingmar Vanhassel, Eric Van
1090 Dewoestine, Sitaram Chamarty, Adam James, Richard Carlsson, Pedro Melo,
1091 AJ Schuster, Phil Jackson, Michael Schwern, Jan Dubois, Christopher J.
1092 Madsen, Matthew Wickline, David Dyck, Jason Porritt, Jjgod Jiang,
1093 Thomas Klausner, Uri Guttman, Peter Lewis, Kevin Riggle, Ori Avtalion,
1094 Torsten Blix, Nigel Metheringham, Gábor Szabó, Tod Hagan, Michael
1095 Hendricks, Ævar Arnfjörð Bjarmason, Piers Cawley, Stephen Steneker,
1096 Elias Lutfallah, Mark Leighton Fisher, Matt Diephouse, Christian
1097 Jaeger, Bill Sully, Bill Ricker, David Golden, Nilson Santos F. Jr,
1098 Elliot Shank, Merijn Broeren, Uwe Voelker, Rick Scott, Ask Bjørn
1099 Hansen, Jerry Gay, Will Coleda, Mike O'Regan, Slaven Rezić, Mark
1100 Stosberg, David Alan Pisoni, Adriano Ferreira, James Keenan, Leland
1101 Johnson, Ricardo Signes, Pete Krawczyk and Rob Hoelz.
1102
1104 Andy Lester, "<andy at petdance.com>"
1105
1107 Copyright 2005-2023 Andy Lester.
1108
1109 This program is free software; you can redistribute it and/or modify it
1110 under the terms of the Artistic License v2.0.
1111
1112 See https://www.perlfoundation.org/artistic-license-20.html or the
1113 LICENSE.md file that comes with the ack distribution.
1114
1115
1116
1117perl v5.38.0 2023-07-19 ACK(1)