From owner-freebsd-fs@FreeBSD.ORG Fri Mar 8 21:43:00 2013 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B2F8C412; Fri, 8 Mar 2013 21:43:00 +0000 (UTC) (envelope-from utisoft@gmail.com) Received: from mail-ea0-x230.google.com (mail-ea0-x230.google.com [IPv6:2a00:1450:4013:c01::230]) by mx1.freebsd.org (Postfix) with ESMTP id 1DA2FBDD; Fri, 8 Mar 2013 21:42:59 +0000 (UTC) Received: by mail-ea0-f176.google.com with SMTP id h10so394284eaj.21 for ; Fri, 08 Mar 2013 13:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0J4rT2dEYWbhS/LXvzR+ZsbgYDeDcfxLZzZtFhKwdOM=; b=YCL1U0alTNahG+VaWqaz9XJx32Ae1YtK9aX1Rl2VtBR5c5nBOUiKZyrQ1N/VLsfRpf kSk50XKTE4gs1SJMmrTTRToMEUKAh8IFPaXs7WTV5SjSBk8ueM1WAd/tjFb6foBBvsao EYjlAuFm7Oup6RsxFSkPLzVTVi5JkcBd8JxRAl+BCjvT9vhUGrmgnrHnJatW5s1Q1VkQ 9FP7gyeRv8xdZ7ekkFTCytgA37bk7+Emfmnfx1ST46f1DWlPAPNnhz7eoec31bGUhkQQ mCMoSMRzRCCBrbPRHtb/jY6WV0KokhLhEAWiOxbAu+ccpT4YbMYDd0WazMIqz3rRevSu D0vw== MIME-Version: 1.0 X-Received: by 10.15.34.198 with SMTP id e46mr9917891eev.27.1362778979183; Fri, 08 Mar 2013 13:42:59 -0800 (PST) Sender: utisoft@gmail.com Received: by 10.14.124.7 with HTTP; Fri, 8 Mar 2013 13:42:58 -0800 (PST) Received: by 10.14.124.7 with HTTP; Fri, 8 Mar 2013 13:42:58 -0800 (PST) In-Reply-To: References: <82112.1362671436.13776555968178880512@ffe17.ukr.net> <20130307161546.GV47829@e-new.0x20.net> <20130308190917.GA34838@lor.one-eyed-alien.net> Date: Fri, 8 Mar 2013 21:42:58 +0000 X-Google-Sender-Auth: ifVkpIn8vzp_yEXhapjIayVn0uA Message-ID: Subject: Re: Argument list too long From: Chris Rees To: Warren Block Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-fs@freebsd.org, Brooks Davis 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 21:43:00 -0000 On 8 Mar 2013 20:05, "Warren Block" wrote: > > 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. The \+ form I have also found impossible to achieve in csh, which is why I never recommend it. Chris (Rees not Ross :)