Linux tools that make you go zoom

Over the past few years I have used Linux almost exclusively for programming and over that time I've gotten comfortable with a lot of the standard utilities. Want to find a file? Use find. Want to find a regexpn in a file? Use grep. It almost seems like a given. Until a little while ago I didn't even question whether there were alternatives since they are pretty much the standard go to tools and have been around forever. More recently I have begun working on larger source trees which I am less familiar with and as a result find myself using these tools a lot more frequently. Whereas previously waiting a bit was acceptable it quickly became a drag for me and I went looking for better alternatives.

I know it seems like a bit of heresy to replace the beloved grep but honestly ack makes it worth it. To show you the difference I'll do a quick search for the string "foobar" in a source tree that's ~500MB and ~9000 files.

Yeah. Seriously. The recursive grep on the directory took over 40 seconds to make it through while ack took under half a second. Anytime you get a two orders of magnitude speedup and its more convenient/fewer characters to type I find it hard to argue against that. The nicest thing about ack is that it automatically ignores all the standard version control files (e.g. .svn) which usually cloud up normal grep results with unwanted results. Of course all that is configurable. So how do you get this magic tool? Its simple:

If your a TextMate user you should be happy to know that there is a awesome bundle which allows you to find text in files really quickly called Ack In Project. I've been using it and found that the interface is awesome and much faster then the grep script I was previously using. The only downside to ack is that the default colors for it are pretty ugly but that can easily be changed via environment variables.

The other thing I frequently need to do is finding files in the file system. Its always something like "where is the config file for X again?" Since those things are frequently in the most bizarre of places I usually end up searching the entire file system which takes forever. Take a look...

Yep, find takes a whole 5+ minutes to get through the file system plus it spits out a bunch of permission denied messages where are really unnecessary in this context. On the other hand locate speeds through and finishes in a second and a half. Nice. The secret sauce is that locate uses a database of the file system the find things much quicker. Since its a standard linux utility and its doing it anyways, so why take advantage? It should be noted that locate searches the entire file system each time while find can search only relative paths so if you are searching a small folder find is usually faster while locate stays pretty constant.

While I'm a fan of the standard linux utilities, but anytime you can find solutions that really speed up things that you do frequently with little or no downside it seems almost foolish to not take advantage of. What are you waiting for?

0 comments:

Post a Comment