On Thu, Sep 11, 2014 at 8:42 AM, Edward Ned Harvey (blu) <b...@nedharvey.com> wrote: > 1- For example, you can do something like > "find somedir -type f -exec grep -l somestring {} \;" > and this adheres to the above principles ... > So then the makers of grep realized they're getting thousands of new > processes spawned and wasting a lot of time, so now you can equivalently > do "grep -lr somestring somedir" which is simpler, more compact, easier to > read/write, and also much faster, because it's integrated.
The original Bell Labs proponents of "do one thing well" accepted that an inefficient shell idiom exposed a new need for a new "one thing" to be done, and that the idiom was a prototype for a new feature that would "do" the new "one thing" "well". Indeed, Bell team added ls -srt quite early, as it was demonstrated as being needed (to avoid alias lss, lst, lssr, lsstr ...). Whether the needed new feature that is implemented as an added grep -r flag or a (hypothetical) find -grep flag or the 'ack' command is a separate matter of taste. (I recommend ack, but that's *my* personal taste. http://beyondgrep.com/ . If you never use real Unix, go ahead and get reliant upon Gnu extensions.) ( Tangential note: There is a "do one thing well" composite solution to find-grep performance too : find ... -print0 | xargs -0 ... is generally superior to find ... -exec ... ';' This can reduce number of spawns by factor of e.g. 900 to 3000 in a modern shell on modern kernel ! $ find . -type f -print0 | xargs -0 perl -E 'say $#ARGV;' # how many args per $ find . -type f -name '*.c' -print0 | xargs -0 grep -i '#include' # or whatever [ Sadly with Win/Mac inspired "spaces in file and directory name for human readability" conventions, the -0 is required for reliability, but find and xargs defaults were set when people knew not to do that. *sigh* ] ) I wonder which "makers of grep" added -r ? I'm guessing it was Team Gnu; it's not a POSIX flag[*]. The SysIII/V, BSD, and Gnu teams all added a lot of flag features to the core executables and built-ins, but Gnu team style is furthest removed from the "do one thing well" style of Bell Labs through v6, PWB, & v7. [*] http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html -- Bill Ricker bill.n1...@gmail.com https://www.linkedin.com/in/n1vux _______________________________________________ Discuss mailing list Discuss@blu.org http://lists.blu.org/mailman/listinfo/discuss