NAME
App::Ack::Intro - An introduction to ack
WHAT ACK CAN DO
Ack is a powerful alternative to grep for programmers. It's made to make a programmer's life easier by optimizing common tasks that programmers face every day.
THE PHILOSOPHY OF ACK
Ack is designed for programmers
Understand ack's idea of the file type
SPECIFY YOUR SEARCHES
Use Perl regular expressions
Auto-escape regular expression metacharacters with -Q
Search without regard to case with -i
Do smart case searching with --smartcase
Match only whole words with -w
Ack can easily be restricted so it only matches whole words, not portions of words, by adding either -w
or --word-regexp
. For example,
ack --w skip
will match lines that have the word "skip" by itself, but will not match strings like "skipping" or "skipped".
This is identical to:
ack '\bskip\b'
CONTROL WHERE YOU SEARCH
Automatically search entire directory trees
Automatically ignore VCS directories
Are you tired of grep finding matches in your CVS, Subversion or Git directories? Even if no matches are found, searching those directories never returns references in source code. ack automatically ignores files contained in the directories for these popular version control systems and many others. If your VCS doesn't have directories already built into ack, you can add them by just adding --ignore-dir
lines to your .ackrc file.
Limit by language with --perl
, --html
, --sql
etc
Exclude languages with --noperl
, --nohtml
, --nosql
etc
Ignore directories from search --ignore-dir
Ack automatically ignores directories having to do with version control systems, but sometimes you just want to exclude a directory for the duration of one command. For example, to keep ack from searching your 'test' directory, use --ignore-dir=test/
.
CONTROL SEARCH RESULTS
Show only the match with -o
Show context lines around the match with -A
, -B
and -C
List only the filename with -l
USE ACK AS A FILE-FINDING TOOL
Open files that ack finds
Need to edit every perl file that calls a particular subroutine? Let ack not only find the files for you (restricting the search to perl files with the --perl
flag), but load them into your editor by using either -l
or --files-with-matches
:
emacs $(ack -l --perl bad_subroutine)
CUSTOMIZE ACK
~/.ackrc
ACK_OPTIONS
TAKE ACK WITH YOU
Put ack in your ~/bin
Ack doesn't have to be installed system-wide for you to use it.
COPYRIGHT & LICENSE
Copyright 2005-2010 Andy Lester.
This program is free software; you can redistribute it and/or modify it under the terms of either:
the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or
the "Artistic License" which comes with Perl 5.
Off the topic of my head:
1. -h (--no-filename) , -l (only filenames) etc. Also exist in GNU grep, but they are still useful.
2. I have this in my .ackrc:
Add Website Meta Language files to .html. --type-add=html=.wml
# Add CMake files --type-set=cmake=.txt,.cmake
[/quote]
Other stuff can be added.
3. -i for case insensitive searches.
5. ack -f for displaying a list of files in the current directory that are not temporary/version-control-related/etc.
6. -a for showing all files.
7. Sometimes I use --nofollow (especially as root).
8. --print0 is useful with xargs (though I haven't used it a lot yet).