Sunday, August 16, 2009

a quickie Unix thing

For those who don't know, I've worked with Unix/Linux/Posix for .. like... longer than I'll admit. And I keep getting into Posix style projects.

This is a really quick thing, but by far the most useful thing about Posix to me is the way you can chain commands. Probably the most coolest command chain that I regularly use, or at least the one I use most often is:

find ./ -name "*.something" -exec egrep -il "somepattern" {} \;

Yeah, for those non-"ix"-ers that syntax is ugly. Ok, for those of us who have been there, it's ugly too.
But what it will do is look through every file named *.something for the pattern "somepattern", ignoring case, and provide a list of all the files that have a pattern match in them (that's what the -l is for).

I use it constantly. Of course there are lots of variations, but the ability to look through a complex directory tree of php files for anything with a certain pattern, when one is totally unfamiliar with the code, is wildly useful.

it's not difficult, but I've run into a few poeple who don't know how to do this and stumble over it using pipes and the like.

Hope it helps someone.

No comments:

Post a Comment