[lug] Limits of grep?

Tkil tkil at scrye.com
Tue Sep 26 08:11:33 MDT 2000


>>>>> "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