The command tries to sum up the sizes:
find . -iname "*.dmg" -exec du -sh '{}' \; 3&> /dev/null |
awk '{print $1}' | summming_up_program???
Can you find a simpler solution?
Ubuntu Solution. Thanks for the Awk-end to Ayman.
find . -iname "*.dmg" -printf '%b\n' |
awk 'BEGIN { s = 0 } {s += $1 } END { print "%dMB", s / 2^20 }'
stat
is used to obtain the size of a file.awk
is used to sum all file sizes.Edit:
A solution that does not fork
stat
:Might be faster then cat'ing the files through the pipe.
wc -c
does not count the bytes, it retrieves the size from inode... or my hdd has a reading speed of 717 GB/s :-)Enhanced Ayman's non-forking command:
Thanks to Ayman for correcting my initial reply.
cat *.dmg | wc -c
cat copies all the files to stdout, and wc counts the size of what was dumped. Nothing gets written to disk.
Not as efficient, but even I can understand it :)