Not grep!
While reviewing some shell scripts last week, I saw the infamous find | grep:
$ /usr/bin/find /foo -type f | egrep -v \*.inp
I am not real sure why more people don’t leverage the logic operations build into find:
$ /usr/bin/find /foo -type f -not -name \*.inp
This saves a fork() and exec(), and should be a bit faster. I am curious if folks use grep because it’s easier to read, or because they don’t know about the logic operations built into find. I shall need to investigate …








Andy Miller on February 10th, 2007
You mean the logic operations built into find? :-) (Since the object is to bypass the fork to grep)
I think one of the reasons is that the find syntax can be somewhat arcane, and even the newest sysadmins know what grep does. By the the time you realize find can do so much more, find | grep is eternally committed to muscle memory.
More seasoned sysadmins might realize (after maintaining one too many ‘what the hell was he thinking when he wrote this?’, or perhaps even more commonly, ‘what the hell was I thinking when I wrote this?’ type scripts) that often clarity wins over efficiency, especially in non-time critical applications.
(So I guess I’m chiming on your poll for a data point of “both :-) )
-Andy