zsh-users
 help / color / mirror / code / Atom feed
* lssum - summing up sizes of files
@ 1998-06-13 16:10 Sven Guckes
  1998-06-13 17:06 ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Guckes @ 1998-06-13 16:10 UTC (permalink / raw)
  To: zsh-users

Does anyone have a nice and small function to sum up the sizes of files?
I know it can be done with awk, sed, and perl - but I just want to use
zsh and its arithmetic.  Is it possible?  And yet fast?

I think I must have asked this before, but - I can't find info on it.
I just hope this isn't a standard example in the zsh manuals - yet.
but I think it should be.  ;-)

Sven


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: lssum - summing up sizes of files
  1998-06-13 16:10 lssum - summing up sizes of files Sven Guckes
@ 1998-06-13 17:06 ` Bart Schaefer
  1998-06-13 19:12   ` Sven Guckes
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 1998-06-13 17:06 UTC (permalink / raw)
  To: Sven Guckes, zsh-users

On Jun 13,  6:10pm, Sven Guckes wrote:
} Subject: lssum - summing up sizes of files
}
} Does anyone have a nice and small function to sum up the sizes of files?
} I just hope this isn't a standard example in the zsh manuals - yet.
} but I think it should be.  ;-)

The manual is woefully short of examples; it's almost exclusively limited
to descriptive text.

In any case, in 3.1.4 with the "stat" module loaded, you can do it with

    sumsizes() {
        local sum sizes i
	stat -A sizes +size $*
	sum=0; for i in $sizes; ((sum += i))
	print sum
    }

E.g.
	sumsizes **/*.o

Replace +size with +block if you want the actual disk block usage.

In 3.0, there's no direct way to read the size of the file into the shell.
You'd have to run "ls" and parse the output, or something.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: lssum - summing up sizes of files
  1998-06-13 17:06 ` Bart Schaefer
@ 1998-06-13 19:12   ` Sven Guckes
  1998-06-13 19:33     ` adding examples to man pages Richard Coleman
  1998-06-13 19:38     ` lssum - summing up sizes of files Danek Duvall
  0 siblings, 2 replies; 7+ messages in thread
From: Sven Guckes @ 1998-06-13 19:12 UTC (permalink / raw)
  To: zsh-users; +Cc: schaefer

Quoting Bart Schaefer (schaefer@brasslantern.com):
> In 3.0, there's no direct way to read the size of the file into the shell.
> You'd have to run "ls" and parse the output, or something.

I see.  Too bad.
And I keep wondering why "gls" doesn't aloow to "sum file sizes".
Doesn't everybody need this kind of thing every day?

> in 3.1.4 with the "stat" module loaded, you can do it with
>     sumsizes() {
>         local sum sizes i
> 	stat -A sizes +size $*
> 	sum=0; for i in $sizes; ((sum += i))
> 	print sum
>     }
> 
> E.g.
> 	sumsizes **/*.o

Looks cool!  We have zsh-3.1.2 here - will that version work?
Or is are "modules" a new feature of zsh-3.1.4?
How do you "load" those modules, anyway?

> The manual is woefully short of examples; it's
> almost exclusively limited to descriptive text.

Indeed - the manuals need more examples.
Is there a good reason for not including them?
(Other than "minimal size"?)

Sven


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding examples to man pages
  1998-06-13 19:12   ` Sven Guckes
@ 1998-06-13 19:33     ` Richard Coleman
  1998-06-13 19:38     ` lssum - summing up sizes of files Danek Duvall
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Coleman @ 1998-06-13 19:33 UTC (permalink / raw)
  To: zsh-users

> > The manual is woefully short of examples; it's
> > almost exclusively limited to descriptive text.
> 
> Indeed - the manuals need more examples.
> Is there a good reason for not including them?
> (Other than "minimal size"?)

It's primarily historical.  Back when I started as maintainer,
the man page for zsh was one big man page (about 90 pages
long).  The man page was so big and cumbersome, no one was
enthusiastic about adding examples to make it longer.

When I split the man page into several smaller man pages, I
always intended to go back and add more examples.  But I never
got that far.  The only man page with any real examples is the
one for zshcomptl.  But that's because Peter rewrote the whole
thing.

But the man pages have generally gotten better with time.  They
are much more readable than they were in the past.  With the
addition of some examples, they would be fine.

The man page which is in the most need of examples is zshexpn.
In particular, we need a few examples to show people that the
modifiers in the History/Modifiers section, also work with
globbing, and parameter expansion (since these are some of the
most useful modifiers that zsh has).

--
Richard Coleman
coleman@math.gatech.edu


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: lssum - summing up sizes of files
  1998-06-13 19:12   ` Sven Guckes
  1998-06-13 19:33     ` adding examples to man pages Richard Coleman
@ 1998-06-13 19:38     ` Danek Duvall
  1998-06-13 21:56       ` Sven Guckes
  1 sibling, 1 reply; 7+ messages in thread
From: Danek Duvall @ 1998-06-13 19:38 UTC (permalink / raw)
  To: zsh-users

On Sat, Jun 13, 1998 at 09:12:33PM +0200, Sven Guckes wrote:

> Quoting Bart Schaefer (schaefer@brasslantern.com):
> > In 3.0, there's no direct way to read the size of the file into the shell.
> > You'd have to run "ls" and parse the output, or something.
> 
> I see.  Too bad.
> And I keep wondering why "gls" doesn't aloow to "sum file sizes".
> Doesn't everybody need this kind of thing every day?

As long as you're using GNU tools, du has a -c option which will sum up the
sizes of the files you specify.  It's perhaps not as flexible as a zsh
script, but for this simple thing, it gets the job done.

Danek


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: lssum - summing up sizes of files
  1998-06-13 19:38     ` lssum - summing up sizes of files Danek Duvall
@ 1998-06-13 21:56       ` Sven Guckes
  1998-06-14  0:20         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Sven Guckes @ 1998-06-13 21:56 UTC (permalink / raw)
  To: zsh-users

Quoting Danek Duvall (duvall@campusclub.princeton.edu):
> > I keep wondering why "gls" doesn't aloow to "sum file sizes".
> As long as you're using GNU tools, du has a -c option which will sum up the
> sizes of the files you specify.  It's perhaps not as flexible as a zsh
> script, but for this simple thing, it gets the job done.

Sure, but - if the zsh has to do globbing anyway
then why not have it looks at the files, too?

As there is a GLOBBING modifier for "size" then I suspect
there must be a nice way to extract the size of files somehow.
Would be nice if there was an easy way to get the sum
without writing an explicit loop for this, too.

I am trying not to ask for a built-in replacement
for gls here - but then again, I wouldn't mind.  ;-)

Sven


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: lssum - summing up sizes of files
  1998-06-13 21:56       ` Sven Guckes
@ 1998-06-14  0:20         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 1998-06-14  0:20 UTC (permalink / raw)
  To: Sven Guckes, zsh-users

On Jun 13,  9:12pm, Sven Guckes wrote:
} Subject: Re: lssum - summing up sizes of files
}
} Doesn't everybody need this kind of thing every day?

I've been using unix for almost fourteen years now (gaah) and I can count
the times I've *needed* that on one hand.  There were a few more times
when I was just curious, but then "wc -c * | tail -1" seemed adequate.

} > 	stat -A sizes +size $*
} 
} Looks cool!  We have zsh-3.1.2 here - will that version work?

I think the stat module is available for 3.1.2.

} Or is are "modules" a new feature of zsh-3.1.4?

No, but they're not in 3.0.

} How do you "load" those modules, anyway?

They're either built in, or if zsh was compiled for dynamic loading, then
you use the "zmodload" command.  "zmodload" works a lot like "autoload",
but searches $MODULE_PATH for a shared library (.so) named for the module.

On Jun 13, 11:56pm, Sven Guckes wrote:
} Subject: Re: lssum - summing up sizes of files
}
} Sure, but - if the zsh has to do globbing anyway
} then why not have it looks at the files, too?

Most globbing can be done by reading the directory structure.  Looking at
the files too is much more expensive.

} As there is a GLOBBING modifier for "size"

File-statistics glob qualifiers (modifiers are qualifiers that change
the string that is returned after the glob succeeds) are used only to
eliminate a file after all the fast pattern matching on its name has
succeeded.

} there must be a nice way to extract the size of files somehow.

That's what the "stat" module is for.

An interesting alternative to the "stat" module would be a glob modifier
that replaces the file name with one of its statistics.  E.g.

echo *(D:#G)

might echo the group-ids of every file in the current directory (:#L for
the size, :#m for the mod time, etc.).  I don't plan to hold my breath
expecting someone to implement this, though.

} Would be nice if there was an easy way to get the sum
} without writing an explicit loop for this, too.

That's an awfully special special-case.  Is there some kind of general
loop replacement that you're thinking of?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-06-14  0:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-13 16:10 lssum - summing up sizes of files Sven Guckes
1998-06-13 17:06 ` Bart Schaefer
1998-06-13 19:12   ` Sven Guckes
1998-06-13 19:33     ` adding examples to man pages Richard Coleman
1998-06-13 19:38     ` lssum - summing up sizes of files Danek Duvall
1998-06-13 21:56       ` Sven Guckes
1998-06-14  0:20         ` Bart Schaefer

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