Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ack: Search directory tree for files with a particular extension

Tags:

ack

I basically just want to do ack foo *.citrus and have ack drill down and find the string 'foo' in all Citrus files in the current directory and below. The trouble is that this won't work if there aren't any Citrus files in the current directory.

I tried messing with -G without success. Do I really need to add a file type in .ackrc just to limit the search to files with a given extension?

like image 886
Mark Wilden Avatar asked Nov 19 '11 20:11

Mark Wilden


3 Answers

As suggested by Andy Lester, you can also create a typeset without taking the trouble to add it in your .ackrc file:

ack --type-set=cit=.citrus --cit "foo"
like image 82
Sébastien Avatar answered Oct 30 '22 02:10

Sébastien


By default, ack searches only in files with known types ( like *.java, *.cpp etc. ). It doesn't know about files *.citrus, so to search in such files you must use -a cmd line switch:

$ack -a -G '\.citrus$' foo
1.d/1.citrus
1:foo_bar
like image 12
Andrey Starodubtsev Avatar answered Oct 30 '22 01:10

Andrey Starodubtsev


You don't have to set it in .ackrc if you don't want. You can also set ACK_OPTIONS in your environment, or specify --type-set arguments on the command line. ack doesn't care.

like image 4
Andy Lester Avatar answered Oct 30 '22 01:10

Andy Lester