TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ack is a grep-like tool, optimised for programmers

186 点作者 quasque大约 11 年前

30 条评论

pie大约 11 年前
It&#x27;s also worth checking out The Silver Searcher: <a href="https://github.com/ggreer/the_silver_searcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ggreer&#x2F;the_silver_searcher</a>
评论 #7710394 未加载
评论 #7710667 未加载
评论 #7710262 未加载
评论 #7710214 未加载
评论 #7710317 未加载
djeikyb大约 11 年前
I use ag[2], which is pretty much the same as ack, but even faster. The other day I was using it to find all instances in all projects of a list of problematic method names[1], in case anyone wants to see a real world use case.<p>[1]: <a href="http://unix.stackexchange.com/questions/108471/no-output-using-parallel-in-tandem-with-ag-or-ack/108472#108472" rel="nofollow">http:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;108471&#x2F;no-output-usi...</a><p>[2]: <a href="https://github.com/ggreer/the_silver_searcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ggreer&#x2F;the_silver_searcher</a>
评论 #7710250 未加载
revscat大约 11 年前
For Java programmers who use Silver Searcher or ack, this lets you search all jars in a directory tree for a given string. Requires GNU Parallel:<p><pre><code> function ffjar() { jars=(.&#x2F;**&#x2F;*.jar) print &quot;Searching ${#jars[*]} jars for &#x27;${*}&#x27;...&quot; parallel --no-notice --tag unzip -l ::: ${jars} | ag ${*} | awk &#x27;{print $1, &quot;:&quot;, $5}&#x27; } </code></pre> Because it uses parallel it spreads the workload across CPUs. I use this frequently when I have to update&#x2F;rewrite&#x2F;create build scripts, and I know a class exists but not which jar file it lives in.
评论 #7711131 未加载
评论 #7711982 未加载
gegtik大约 11 年前
It should be noted that &quot;faster&quot; is due to the fact that it limits itself to searching the subset of files that have code extensions.<p>I&#x27;ve tested grep against ack and ag for large text files and grep won handily, especially the latest version of grep.<p>Also note you can use GNU Parallel to run multiple greps
评论 #7710296 未加载
评论 #7712532 未加载
616c大约 11 年前
For some reason, it took me one or two minutes of rereading to realize it was ack, not awk. I think this website was going to be some ironic trash-talking about grep. Then I saw &quot;written in Perl&quot; and I got so confused my head almost exploded.<p>Anyway, neat tool. Will check it out soon.
评论 #7712270 未加载
jaredmcateer大约 11 年前
I&#x27;m assuming the title got rewritten? It is probably important to note:<p>&quot;ack versions 2.00 to 2.11_02 are susceptible to a code execution exploit. Please upgrade to 2.12 or higher ASAP.&quot;
评论 #7710365 未加载
cake大约 11 年前
I couldn&#x27;t live without this tool today, very useful to quickly find where <i>that</i> method is used for example.
评论 #7710213 未加载
senthilnayagam大约 11 年前
<a href="https://github.com/monochromegane/the_platinum_searcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;monochromegane&#x2F;the_platinum_searcher</a> I use pt for stuff which is not in git, written in go and it is fast
评论 #7714766 未加载
pretz大约 11 年前
It&#x27;s worth noting that if you&#x27;re always searching in a git repo, git-grep is pretty comparable to ack and you already have it installed.
评论 #7710568 未加载
antisocial大约 11 年前
My ex-colleague introduced this to me and I thank him every time I use ack. It is really so much better than grep. I have set up a bunch of aliases to search by file type and it makes me so productive.
foz大约 11 年前
I used Ack a lot when I was coding Perl (it&#x27;s been a while). After I switched to Ruby, I used rak [1], which seemed easier to use most of the time, and nearly identical.<p>However, when you just want to find stuff fast, it&#x27;s annoying to have to deal with Perl&#x2F;CPAN or RVM&#x2F;Rubygems, especially when the dependencies are not installed on your server&#x2F;workstation.<p>That&#x27;s why I&#x27;ve switched to silver searcher (ag) [2], as it can be installed with any OS package manager (brew, apt, yum).<p>[1] <a href="http://rak.rubyforge.org" rel="nofollow">http:&#x2F;&#x2F;rak.rubyforge.org</a> [2] <a href="https://github.com/ggreer/the_silver_searcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ggreer&#x2F;the_silver_searcher</a>
评论 #7712439 未加载
gejjaxxita大约 11 年前
The problem with such tools is often their lack of ubiquity. I don&#x27;t want to start using ack, forget a lot of my grep knowledge, only to ssh into a server and need grep.<p>The benefit of grep&#x27;s ubiquity outweighs any small advantage ack has in usability.
评论 #7710789 未加载
评论 #7711104 未加载
andrelaszlo大约 11 年前
Old thread here: <a href="https://news.ycombinator.com/item?id=6075083" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6075083</a>
eliben大约 11 年前
Similar tool in pure Python: <a href="https://github.com/eliben/pss" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;eliben&#x2F;pss</a>
评论 #7711011 未加载
petdance大约 11 年前
There&#x27;s a list of other tools for search source code besides ack at <a href="http://beyondgrep.com/more-tools/" rel="nofollow">http:&#x2F;&#x2F;beyondgrep.com&#x2F;more-tools&#x2F;</a>, including other grepalikes and indexing tools like ctags and cscope.<p>I suggest that you need not limit yourself to only one tool for your code searching. Toolboxes FTW.
sitaramc大约 11 年前
Grep is just as good, and with the recent order of magnitude speed improvement on non-C locales that they made -- see <a href="https://lwn.net/Articles/586899/" rel="nofollow">https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;586899&#x2F;</a> -- which may not have made its way into distros yet, it&#x27;s easily the best option.<p>I have a simple wrapper over egrep (see <a href="https://github.com/sitaramc/ew" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sitaramc&#x2F;ew</a> ) that adds those little extras (ignoring binary files, ignoring VCS directories...).<p>I&#x27;m sure it&#x27;s improved since the days I tried it, but I tend to be permanently prejudiced against tools where the author can&#x27;t&#x2F;won&#x27;t document the file selection logic and says &quot;there&#x27;s really no English that explains how it works&quot; when someone asks.
TorKlingberg大约 11 年前
Ack is great, but watch out if you have any source files with unusual file name extensions. Ack will only search file types it knows about. Also if you have your whole source tree in your editor or IDE, then you may as well search there instead.
评论 #7710305 未加载
评论 #7710283 未加载
评论 #7710511 未加载
raverbashing大约 11 年前
Yeah, I think grep sucks as well, that&#x27;s why I created my own little ack thing<p>(since it&#x27;s in a sorry state I won&#x27;t post it here, and it will attract the rage of people for not being compatible with grep&#x2F;in python&#x2F;no docs&#x2F;etc)
bch大约 11 年前
How does this compare to cscope[0] ?<p>edit: or ctags[1] ?<p>---<p>[0] <a href="http://en.wikipedia.org/wiki/Cscope" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cscope</a><p>[1] <a href="http://en.wikipedia.org/wiki/Ctags" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Ctags</a>
评论 #7711000 未加载
VeejayRampay大约 11 年前
I recently found out about git-grep. It&#x27;s good and quite fast.
herokusaki大约 11 年前
Is there a tool that is to find what ack is to grep?
评论 #7710538 未加载
评论 #7710404 未加载
评论 #7713306 未加载
评论 #7711018 未加载
0x0大约 11 年前
I used this for a while, but got bitten by the fact that, by default, it does not search all file types. :-&#x2F;
omegote大约 11 年前
Been using ack-grep for years. In systems where it&#x27;s not installed I just use grep -Hnir
olalonde大约 11 年前
Is there a code repository somewhere? Can&#x27;t seem to find one...
评论 #7710272 未加载
评论 #7710274 未加载
davexunit大约 11 年前
I&#x27;ll stick with grep, thanks. M-x rgrep in Emacs works great.
评论 #7710351 未加载
NicoJuicy大约 11 年前
This has found it&#x27;s way to HN a long long time ago:<p><a href="https://news.ycombinator.com/item?id=975511" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=975511</a>
username42大约 11 年前
Why did they choose the same name as minix compiler ack (<a href="http://tack.sourceforge.net/" rel="nofollow">http:&#x2F;&#x2F;tack.sourceforge.net&#x2F;</a>) ?
anotherevan大约 11 年前
And just to warp things even further, use ack to find the files you&#x27;re after, then run through grep:<p><pre><code> ack -f --css | parallel grep search_term</code></pre>
fdsary大约 11 年前
I thought we were done with this already? <a href="https://github.com/ggreer/the_silver_searcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ggreer&#x2F;the_silver_searcher</a>
Antwan大约 11 年前
Seen <a href="http://beyondgrep.com/security/" rel="nofollow">http:&#x2F;&#x2F;beyondgrep.com&#x2F;security&#x2F;</a><p>Didn&#x27;t read further.