From owner-freebsd-fs@FreeBSD.ORG Fri Mar 8 20:05:50 2013 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id CB479615; Fri, 8 Mar 2013 20:05:50 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) by mx1.freebsd.org (Postfix) with ESMTP id 803CF7DC; Fri, 8 Mar 2013 20:05:50 +0000 (UTC) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.14.6/8.14.6) with ESMTP id r28K5fAF089779; Fri, 8 Mar 2013 13:05:41 -0700 (MST) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.14.6/8.14.6/Submit) with ESMTP id r28K5fvX089776; Fri, 8 Mar 2013 13:05:41 -0700 (MST) (envelope-from wblock@wonkity.com) Date: Fri, 8 Mar 2013 13:05:41 -0700 (MST) From: Warren Block To: Brooks Davis Subject: Re: Argument list too long In-Reply-To: <20130308190917.GA34838@lor.one-eyed-alien.net> Message-ID: References: <82112.1362671436.13776555968178880512@ffe17.ukr.net> <20130307161546.GV47829@e-new.0x20.net> <20130308190917.GA34838@lor.one-eyed-alien.net> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (wonkity.com [127.0.0.1]); Fri, 08 Mar 2013 13:05:41 -0700 (MST) Cc: freebsd-fs@freebsd.org X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Mar 2013 20:05:50 -0000 On Fri, 8 Mar 2013, Brooks Davis wrote: > 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" {} \+ There is a typo, should be "-type f". > This won't include file names and is gratuitously inefficient starting one > grep per file. But the final \+ means "{} is replaced with as many pathnames as possible for each invocation of utility. This behaviour is similar to that of xargs(1)." > 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. For fun, after running each of these several times to preload cache: find /usr/ports -type f -print0 | xargs -0 grep -H "X-PHP-Script" 40.98 seconds (average) find /usr/ports -type f -exec grep -H "X-PHP-Script" {} \+ 42.27 seconds (average) So they aren't too different in performance.