Hacker Public Radio

HPR3911: An overview of the 'ack' command


Listen Later

Introduction
I have occasionally been using a tool called ack for a
few years now. It’s billed as “an alternative to grep for
programmers”.
There are several features I find particularly useful:
It can restrict text searches to files of a particular
type
It uses Perl regular expressions which may be the most powerful
and feature rich types of RE’s available at present
You can limit the search area within a file if desired
It is a very comprehensive and useful tool, though maybe quite
complex to use. Personally I use it in special cases where I need its
power, and otherwise use the usual grep.
In this episode I will give you the flavour of its capabilities and
otherwise leave you to research more if it sounds interesting.
Installing ack
The tool can be found in repositories. I use Debian, and
ack is in the Debian repo and can be installed with:
sudo apt install ack
Installing it this way the version I have (and am describing here) is
3.6.0. There is a new version, 3.7.0 available from the website.
The documentation on the website suggests installing it as a Perl
module using CPAN, which is something I will do soon I
think.
Perl regular expressions
These are very sophisticated.
A project to convert the Perl regular expression capabilities into a
portable library form was undertaken by Philip Hazel of Cambridge
University in 1997, and was called Perl Compatible Regular
Expressions or PCRE.
Philip Hazel was the originator of the exim mail
transfer agent (MTA, or mail server), and wanted to use PCRE within
it.
Since then PCRE (and later PCRE2) is the way regular expressions are
implemented in a lot of other software, which shows how widespread use
of the Perl RE has become.
The ack documentation refers to the Perl manual for
details of this type of regular expression, and to a tutorial, if you
wish to gain a deeper understanding.
It should be noted that GNU grep can use Perl compatible
regular expressions when matching lines in files, but this feature is
marked as experimental.
File types
The ack command has rules for recognising file types. It
does this by looking at the name extensions ('.html' or
'.py' for example), and in some cases by examining their
contents. The complete list of types can be found by running:
ack --help-types
… or, for a more detailed but less readable list:
ack --dump
Some examples are:
cc for C files
haskell for Haskell files
lua for Lua files
python for Python files
shell for Bash, and other shell command files
These names can be used with the options -t TYPE and
--type=TYPE and also by simply preceding them with two
dashes (--TYPE). There are also ways of requesting files
not of a given type: -T TYPE, --type=noTYPE
and --noTYPE.
To check files in the current directory of type shell an
ack command like the following might be used and the
following type of output produced:
$ ack --shell declare
Bash_snippet__using_coproc_with_SQLite/examples/coproc_test.sh
11:declare -a com=('date +%F' 'whoami' 'id' 'echo "$BASH_VERSION"'
Note that ack reports the file path and numbered lines
within it that match.
You can
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

373 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

653 Listeners

Curious Cases by BBC Radio 4

Curious Cases

829 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

422 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,044 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,799 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners