From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9930 invoked by alias); 3 Sep 2011 21:59:47 -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: 16310 Received: (qmail 21334 invoked from network); 3 Sep 2011 21:59:35 -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: <110903145915.ZM11992@torch.brasslantern.com> Date: Sat, 03 Sep 2011 14:59:15 -0700 In-reply-to: <20110903192316.GA14785@toggle.be> Comments: In reply to Thor Andreassen "Re: listing sub-drectories with most files in" (Sep 3, 9:23pm) References: <20110903120208.GC11672@toggle.be> <110903081320.ZM9630@torch.brasslantern.com> <20110903192316.GA14785@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 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. 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.