Reputation: 2051
Sure, find -exec
allows me to used stat
to get file size, and a tiny Python one-liner to sum that:
find . -name "*.sh" -exec stat -f '%z' {} \; | python -c'import sys; print sum(int(x) for x in sys.stdin)'
There could be a use of bc
, I guess, to make that more bash-like.
However, (The question), I already have a list of files, find -exec
is out. How do I tersely and elegantly get the file sizes in a pipe. I could use a xargs
and du|cut
pipeline, but despite -s
on xargs, I run the risk of blowing up the command length or having to over-allocate to the tune of gigabytes.
I'm hoping for something that can calculate disk usage and do so in a standard-in centric way:
cat myList.txt -exec stat -f '%z' {} \; | python -c'import sys; print sum(int(x) for x in sys.stdin)'
Cat doesn't have an -exec though :-(
Upvotes: 1
Views: 101
Reputation: 158020
You can use a pipe with xargs du
and awk
:
xargs -a file.list du -b | awk '{t+=$1}END{print t}'
That gives you the accumulated size in bytes.
Upvotes: 2