[TAG] 2-cent tip: Summing up file sizes
Ben Okopnik
ben at linuxgazette.net
Sun Jul 15 02:28:57 MSD 2007
On Sat, Jul 14, 2007 at 09:58:00PM +0100, Neil Youngman wrote:
> On or around Saturday 14 July 2007 17:05, Neil Youngman reorganised a bunch of
> electrons to form the message:
> > On or around Saturday 14 July 2007 15:12, Ben Okopnik reorganised a bunch
> > of electrons to form the message:
> >
> > > I do have to say that this solution is much faster than my "for" loop -
> > > so I'll update the script a bit. Incidentally, note the "du -bS" usage:
> > > I've played around with the "du" options, and there doesn't seem to be a
> > > way to tell it to display just the sum, in bytes, of a group of files.
> > > Seems rather silly... but that's OK; an accumulator isn't hard to write
> > > in "awk" or whatever.
> >
> > I thought -bc would do it
> >
> > -c, --total
> > produce a grand total
> >
> > but their idea of a "grand total" isn't quite what I meant by a "grand
> > total".
>
> No, actually it is the same.
Were you getting the directory sizes before? That's why I've been adding
'-S' into the mix.
> 503 > du -bc *.txt | tail -1
> 47492 total
> 504 >
>
> Doh.
``
du -Sbc $(cat "$1")|tail -1|cut -f1
''
is only a little shorter than what we've got now; I don't know that we
can squeeze a whole lot more out of it. :)
--
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG
mailing list