Argument list too long

Brooks Davis brooks at freebsd.org
Fri Mar 8 19:09:25 UTC 2013


On Thu, Mar 07, 2013 at 05:15:46PM +0100, Lars Engels wrote:
> On Thu, Mar 07, 2013 at 05:50:36PM +0200, Vladislav Prodan wrote:
> > Why 12K small files from one directory to cause problems?
> > 
> > # ll | wc -l
> >    11467
> > 
> > # grep X-PHP-Script * | more
> > /sbin/grep: Argument list too long.
> > 
> > # egrep X-PHP-Script *.ua | more
> > /usr/sbin/egrep: Argument list too long.
> > 
> > # cat *.ua | grep X-PHP-Script | more
> > /sbin/cat: Argument list too long.
> > 
> > 
> > 
> 
> Your shell can't process that many arguments. Use this:
> 
> grep -R "X-PHP-Script" .
> 
> or if you don't want to descent into subdirectories:
> 
> find . -type -f -name '*.ua' -maxdepth 1 -exec grep "X-PHP-Script" {} \+

This won't include file names and is gratuitously inefficient starting one
grep per file.  The command you're looking for is:

find . -type -f -name '*.ua' -maxdepth 1 -print0 | xargs -0 grep -H "X-PHP-Script"

The find -print0 | xargs -0 allows filenames to contain spaces.  The
grep -H is mostly theoretical in that the last grep invocation by xargs
couple only include one file and thus wouldn't include the filename.

-- Brooks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20130308/b02fcd4e/attachment.sig>


More information about the freebsd-fs mailing list