Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Summary: Sorting files

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


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:   


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


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...


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)
      ls -l ${i}

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(.)


"--" 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!

> 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

Messages sorted by: Reverse Date, Date, Thread, Author