[TAG] 2-cent tip: Summing up file sizes
Ben Okopnik
ben at linuxgazette.net
Sun Jul 15 18:33:00 MSD 2007
On Sun, Jul 15, 2007 at 10:02:45AM +0100, Neil Youngman wrote:
> On or around Saturday 14 July 2007 23:28, Ben Okopnik reorganised a bunch of
> electrons to form the message:
> > Were you getting the directory sizes before? That's why I've been adding
> > '-S' into the mix.
>
> You shouldn't be seeing directory sizes from du unless you're passing it
> parameters.
>
> I get the exact same output for 'du -Sbc *.txt' as I do for 'du -bc *.txt'
You're right; I'm just going for the belt and suspenders approach. The
reason I published the 2-cent tip in the first place was because of the
two useful techniques in it - summing up file sizes from a disparate
list of files and parsing a large number; in the case of a list of MP3s,
the question of directories will, of course, be moot, but not if it's
used on arbitrary lists. In fact, there probably needs to be a definite
and explicit mechanism for ignoring directories; in the case of the
former "for" loop that I was using, saying
``
[ -f "$n" ] && ((total+=$size))
''
would do it, whereas for using "du", you'd just want to make sure that
you don't specify any directories (i.e., instead of saying "du foo/",
you'd want to say "du foo/*".)
``
ben at Tyr:/tmp$ mkdir foo
ben at Tyr:/tmp$ for n in `seq 5`; do head -1000c /dev/full > foo/$n; done
ben at Tyr:/tmp$ du -bc foo/|tail -1 # WRONG!
9096 total
ben at Tyr:/tmp$ du -bc foo/*|tail -1 # Right.
5000 total
''
--
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG
mailing list