zsh-users
 help / color / mirror / code / Atom feed
From: Thor Andreassen <ta@toggle.be>
To: zsh-users@zsh.org
Subject: Re: listing sub-drectories with most files in
Date: Sun, 4 Sep 2011 02:34:00 +0200	[thread overview]
Message-ID: <20110904003400.GB14785@toggle.be> (raw)
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


  reply	other threads:[~2011-09-04  0:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-02 15:24 zzapper
2011-09-02 17:03 ` Bart Schaefer
2011-09-02 18:30   ` zzapper
2011-09-02 18:59     ` Bart Schaefer
2011-09-03 12:02 ` Thor Andreassen
2011-09-03 15:13   ` Bart Schaefer
2011-09-03 19:23     ` Thor Andreassen
2011-09-03 21:59       ` Bart Schaefer
2011-09-04  0:34         ` Thor Andreassen [this message]
2011-09-10 17:53   ` Aaron Davies
2011-09-10 19:37     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110904003400.GB14785@toggle.be \
    --to=ta@toggle.be \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).