zsh-users
 help / color / mirror / code / Atom feed
From: Meino Christian Cramer <Meino.Cramer@gmx.de>
To: david@tvis.co.uk
Cc: zsh-users@sunsite.dk
Subject: Summary: Sorting files
Date: Sat, 06 Aug 2005 07:38:35 +0200 (CEST)	[thread overview]
Message-ID: <20050806.073835.71083870.Meino.Cramer@gmx.de> (raw)
In-Reply-To: <g3h6f1tsnq5ae63mane269rma0ao8r3ua3@4ax.com>

From: zzapper <david@tvis.co.uk>
Subject: Re: Sorting files
Date: Fri, 05 Aug 2005 11:51:15 +0100




*** PRELIMINARY DRAFT ***




Sorting files: Summary of traps and pitfalls 

To achieve more control over wildcards -- or should I better separate
"wild" from "cards" ;O) -- zsh has implemented "Glob qualifiers".

One of these "Glob Qualifiers" is "oL", which sorts all files matching
the wildcard. Example:   

	*.bz2(oL) 

will match all bzip2-compressed files in the current directory and
sort the list by the size of that files.

More interesting effects can be achieved, when "(oL)" is combined with
recursive globbing.

The wildcard

	**/*.bz2

will result in a list of all bzip2-compressed files in the current
directory and all subdirectories below.

So far so nice... ;O)

Now...what will be the result if one submit

	ls -l **/*.bz2(.oL)

? Confusion -- at least in my case... ;)

Beside the common "arg list too long" failure of ls, which appears,
when "**/*.bz2" simply will to match too many files, the output isn't
sorted the exspected way...

Why?

First **/*.bz2 will be evaluated. The result is a sorted (!) list of 
files. Then ls grabs that list and resorted it the standard way
(alphabetically), which destroy the sort done by (.oL).

One way around this trap is a "longer" script:

    for i in **/*bz2(.ol)
    do
      ls -l ${i}
    done

which won't give ls the chance of sorting anything, cause it only sees
one file at a time. The drawback is a call to ls on *every* file and a 
somehow bulky command.

If you get an "arg list to long"-error after submitting

   ls -l **/*bz2(.oL)

then the above script is a solution for that. But if not the following
does, what you want:

   ls -sS -- **/*.bz2(.)

Why?

"--" prevents ls from thinking of another option, if a filename starts
with a "-". "-s" let ls print the size of the file, "-S" sort the
files matching **/*.bz2(.) by its size.

Or in other words: (.oL) to sort files is not needed here and it seems
that in combination with recursive globbing plus ls it spend a lot of
confusion to its users (this is at least valid for me ;).

Keep zshing!
Meino


> On Thu, 4 Aug 2005 21:51:33 +0200,  wrote:
> 
> >Meino Christian Cramer wrote:
> >> Hi,
> >>
> >>  I played around with combinations including expressions like
> >>  **/*(.,oL) trying to get a listing of all files found !including
> >>  those of the subdirectories! sorted by their size. I want one big
> >>  listing sorted "once" -- but I got "seperated" parts sorted each for
> >>  themselves.
> 
> Any chance of a summary of this interesting thread (assuming it's finished)?
> -- 
> zzapper
> vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
> http://www.rayninfo.co.uk/tips/ vim, zsh & success tips
> 


  parent reply	other threads:[~2005-08-06  5:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-04 18:38 Meino Christian Cramer
2005-08-04 18:48 ` Mikael Magnusson
2005-08-04 19:10   ` Meino Christian Cramer
2005-08-04 19:18     ` Danek Duvall
2005-08-04 20:41       ` Stephane Chazelas
2005-08-05  3:01         ` Meino Christian Cramer
2005-08-05 10:47           ` Stephane CHAZELAS
2005-08-04 19:14 ` Christian Schneider
2005-08-04 21:19   ` Jens Kubieziel
2005-08-05  3:06   ` Meino Christian Cramer
2005-08-04 19:51 ` Christian Taylor
2005-08-05 10:51   ` zzapper
2005-08-05 12:57     ` Christian Taylor
2005-08-05 14:41     ` Meino Christian Cramer
2005-08-06  5:38     ` Meino Christian Cramer [this message]
2005-08-06  9:22       ` Summary: " Christian Taylor
2005-08-05 12:52 ` DervishD
2005-08-05 14:01   ` Meino Christian Cramer
2005-08-05 14:29     ` Mikael Magnusson

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=20050806.073835.71083870.Meino.Cramer@gmx.de \
    --to=meino.cramer@gmx.de \
    --cc=david@tvis.co.uk \
    --cc=zsh-users@sunsite.dk \
    /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).