[lug] Limits of grep?

Atkinson, Chip CAtkinson at Circadence.com
Tue Sep 26 16:33:45 MDT 2000


I just discovered why the "-print0" and the "xargs -0" -- It works with
files with spaces in the name.  Worth knowing.  

Chip

-----Original Message-----
From: Tkil [mailto:tkil at scrye.com]
Sent: Tuesday, September 26, 2000 8:12 AM
To: lug at lug.boulder.co.us
Subject: Re: [lug] Limits of grep?


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

_______________________________________________
Web Page:  http://lug.boulder.co.us
Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug




More information about the LUG mailing list