Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: listing sub-drectories with most files in
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. :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author