Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Summary: Sorting files
- X-seq: zsh-users 9254
- From: Meino Christian Cramer <Meino.Cramer@xxxxxx>
- To: david@xxxxxxxxxx
- Subject: Summary: Sorting files
- Date: Sat, 06 Aug 2005 07:38:35 +0200 (CEST)
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <g3h6f1tsnq5ae63mane269rma0ao8r3ua3@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
From: zzapper <david@xxxxxxxxxx>
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
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author