Calculate size of files in shell
Try:
find . -name "*.undo" -ls | awk '{total += $7} END {print total}'
On my system the size of the file is the seventh field in the find -ls
output. If your find … -ls
output is different, adjust.
In this version, using the existing directory information (file size) and the built-in ls feature of find should be efficient, avoiding process creations or file i/o.
With zsh, you can use extended globbing to do:
du -c **/*.undo
find -name *.undo -print0 | du -hc --files0-from=-
du -c *pattern*
This will print the total on the last line of output.