From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9565 invoked by alias); 4 Sep 2011 00:34:04 -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: 16311 Received: (qmail 8452 invoked from network); 4 Sep 2011 00:34:02 -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 toggle.be does not designate permitted sender hosts) Date: Sun, 4 Sep 2011 02:34:00 +0200 From: Thor Andreassen To: zsh-users@zsh.org Subject: Re: listing sub-drectories with most files in Message-ID: <20110904003400.GB14785@toggle.be> Mail-Followup-To: zsh-users@zsh.org References: <20110903120208.GC11672@toggle.be> <110903081320.ZM9630@torch.brasslantern.com> <20110903192316.GA14785@toggle.be> <110903145915.ZM11992@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <110903145915.ZM11992@torch.brasslantern.com> On Sat, Sep 03, 2011 at 02:59:15PM -0700, Bart Schaefer wrote: > On Sep 3, 9:23pm, Thor Andreassen wrote: > } > } Adding -maxdepth 1 and -type f to find should limit the result > } correctly: > } > } find *(/) -maxdepth 1 -type f | cut -d/ -f1 | uniq -c | sort -n > > Unfortunately that's still not quite right. Because you've lost the > path leading up to the subdirectory name, if two subtrees each contain > a directory with an identical name, you'll either get two counts with > no way to distinguish them, or a single count that is the sum of the > number of files in both of those subdirectories. My brain is working slower than usual, sorry about the confusion. After re-rereading the OP question, and properly testing your solution I now get it. > Also because find prints in directory scan order, you have to be careful > or you'll get a few files and then a subdirectory and then a few more > files and you'll still end up with multiple counts for the same directory. > > You can do it this way: > > find *(/) -type f -exec dirname {} \; | sort | uniq -c | sort -n > > but that seems like an awful lot of work. Agreed, a slightly improved version, but still a lot of work: find . -type d | while read dir; do find $dir -maxdepth 1 -type f | wc -l | tr -d '\n'; print ":$dir" done | sort -n But nowhere near as efficient or elegant as the suggested zsh solution, sorry about the noise and thank you for your patience :). -- best regards Thor Andreassen