[lug] Limits of grep?

Hugh Brown hugh at math.byu.edu
Tue Sep 26 20:38:25 MDT 2000


Glad to know the facts.  This is why I tend to include the "I think"
when I'm not sure.  Also good to know how I can use find more
effeciently.

Hugh

Tkil wrote:
> 
> >>>>> "Hugh" == Hugh Brown <hugh at math.byu.edu> writes:
> 
> Hugh> This is a limitation of the shell most likely (on the order of
> Hugh> 256 characters, I think).
> 
> most unix shells are limited to 4096 characters.  bash is limited to
> about 4000 *words* on the command line (and even that might not be a
> bash limit, so much as a libc/crt0 issue with argc/argv.)
> 
> Hugh>    find . -type f -exec grep "search pattern" {} \;
> 
> note that this is horribly inefficient, as it blasts off a new process
> for every file.  the xargs approach is much better in this respect.
> 
> also, `find' is recursive by default; if there are any subdirectories
> in the current directory, something like this might be preferred:
> 
>    find . -type f -maxdepth 1 -print0 | xargs -0 grep '...'
> 
> the other way i occasionally attack problems like this is with perl,
> using its opendir/readdir/closedir builtins.
> 
> t.






More information about the LUG mailing list