Getting file sizes
Paul Lussier
p.lussier at comcast.net
Mon Oct 22 09:56:46 EDT 2007
Kent Johnson <kent37 at tds.net> writes:
> Newbie question:
>
> How can I get the total size, in K, of all files in a directory that
> match a pattern?
Stephen Ryan <stephen at sryanfamily.info> writes:
> du -c *.txt | tail -1
>
> du prints out the sizes of each of the matching files; '-c' means you
> want a total, too; piping the output through tail -1 picks out just the
> last line with the total.
Hmmm, I wouldn't have chosen 'tail -1'. My instinct would have been
to 'grep -i total', which is both more typing, and not as accurate
(what if there was a filename containing the string 'total'?).
"Michael ODonnell" <michael.odonnell at comcast.net> writes:
> du -c -h --files0-from=<(find . -xdev -type f -name "*.jpg" -print0 \
> 2>/dev/null) | tail -1
Hmm, again, certainly not my fist instinct :)
I almost *never* think to redirect stdin this way for some reason.
Had I come up with the answer, I probably would have written it more
like:
find . -type f -name \*.muse -print0 | du -c --files0-from=- | tail -1
Which yields the same answer. I think I like mod's better :)
Ted Roche <tedroche at tedroche.com> writes:
> To get the result in K, specify:
>
> du -c --block-size=1024 *.txt
Hmmm, I would have just used -k, or actually, let it default to that
and not specify any flag at all regarding size.
> or your choice of what you think K means ;)
Though, it's very cool that you can specify exactly what you mean here.
> man du tells more.
Indeed it does! What a great little thread! :)
--
Seeya,
Paul
More information about the gnhlug-discuss
mailing list