From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21553 invoked by alias); 8 Sep 2016 21:48:33 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21855 Received: (qmail 22931 invoked from network); 8 Sep 2016 21:48:33 -0000 X-Qmail-Scanner-Diagnostics: from mail-qk0-f174.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.174):SA:0(0.0/5.0):. Processed in 1.717799 secs); 08 Sep 2016 21:48:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=sY1kso4ZGV+Cz02sAJeTisMrI00C5DfsLXbs+hKThP4=; b=Q5B03xMMDXXKprUHbDE3dqcdnVwZ3OICD9iN1PlQNY46xPU+hF9w9mBZRn1Y3GrBJr GWAzphFBmUvmhmT/JLFyS3HaMRAsNwdYydolahVjOjd0urn61zkvL1/ZmiowCwpskRCa 4gLIx2EMwO/fIqsrW9C9EtVacr3XhKD94jj+rVrwES243nHvLZxsgiENsc7dVZH+/sV2 ojXFU+en0E/r3QA/IfqU9oLij+3B4HLRQlguJwfBE/1gREGyvL3kKAD5L1kXV8L3XfYm W8Svnr38XgpUuy6NUzEQ9rmZFGczRgJZrtbsSyRQk6dlUAtFsHLV0BYxU49c0yVZM2jd 2g0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=sY1kso4ZGV+Cz02sAJeTisMrI00C5DfsLXbs+hKThP4=; b=crlsOCXLr50ZAVPSsWMGGqWLYGLWT50HvX//DhKGmbCgUSXhwZUATCOpNfOHZBDMal 44M+BBwT2rkeNgG+l7eg2MNVQvv2lXQoAkth9A49LFXNn0a/dLrhorI4kBVYeUUKDX2f 8q0CtsgZZ7SfNC1b+TXTFXwVH0KACoc2SV8uNWKOJZdICCcgGLcAgnr46MgMadyK9obf DomRKvidxHK0G10nFSHC4iuHsFodTfNiTWEK+N77Z0O53bXS0Dqc9qXzbQOf23+qeWV7 m3KQyIUr/MM8KbfvuVYNZNR55Jy9Bn87v0UwlFXcUu6/Xy1d6Y1jvv6hU/38qJi0TOeB bZJA== X-Gm-Message-State: AE9vXwPbR7MK7Tt+eb3DF3Ru27irGjzveK4Di3SBOfiwYZKoETk7FoGqWfLVAwtXyPO74gcafQqxIZYKqy2xyw== X-Received: by 10.55.162.13 with SMTP id l13mr1897113qke.72.1473364818858; Thu, 08 Sep 2016 13:00:18 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <160908090800.ZM13466@torch.brasslantern.com> From: Bart Schaefer Date: Thu, 8 Sep 2016 13:00:18 -0700 Message-ID: Subject: Re: Fastest way to count # of files? To: Zsh Users Content-Type: text/plain; charset=UTF-8 On Thu, Sep 8, 2016 at 9:37 AM, Sebastian Gniazdowski wrote: > First ran was slower than this and following ones: > > % typeset -F SECONDS; myst=$SECONDS; integer nfiles=0; : > **/*(Ne?'((++nfiles)) && reply=()'?); print $nfiles; echo $(( (SECONDS > - myst) * 1000 )) > 80001 > 1427.3609999982 > > I.e. 1.4 second It may be using more time than your original example because of the **/ recursion. The only other option I can think of is this: integer nfiles=0 typeset -a nlink zmodload zsh/stat : **/*(/Ne?'zstat -A nlink +nlink $REPLY && ((nfiles += $nlink - 2)); reply=()'?) print $nfiles This assumes that nlink for a directory is the number of files it contains plus "." and "..". However, the result I get is off by a little from the glob without directory filtering.