From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1352 invoked by alias); 10 Sep 2011 19:37:58 -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: 16332 Received: (qmail 18696 invoked from network); 10 Sep 2011 19:37:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110910123729.ZM18232@torch.brasslantern.com> Date: Sat, 10 Sep 2011 12:37:29 -0700 In-reply-to: Comments: In reply to Aaron Davies "Re: listing sub-drectories with most files in" (Sep 10, 1:53pm) References: <20110903120208.GC11672@toggle.be> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: listing sub-drectories with most files in MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 10, 1:53pm, Aaron Davies wrote: } } (for d (**/*(/)) echo `ls $d|wc -l` $d)|sort -n These are all good tries, but `ls $d` will include subdirectory names as well as file names; the original request was for a count of files. Further you have to worry whether there's an alias for "ls" that may change it from listing one file per line. If you use `print -l $d/*(N.)` you fix both of these problems, but you're still forking `wc -l`. Try ${#$(print -l $d/*(.))} ? Replace ( ... ) with { ... } to avoid unnecessary subshells: { for d (**/*(/)) print ${#$(print -l $d/*(.))} $d } | sort -n On my desktop that's 10x faster than using `ls|wc` but still 2x slower than my all-globbing solution. OTOH the all-globbing solution might take 5x as long to type. :-)