Shell snippets: sum file sizes

by Rudd-O published 2018/11/18 12:54:09 GMT+0, last modified 2018-11-18T12:54:09+00:00
Quick one-liner to add up the (apparent) disk space taken up by files.

The following sample adds up the disk space of image files in the current directory and below, and shows it onscreen, in gibibytes.

find -name *.img -type f | xargs python -c \
'import sys, os ; print sum(os.stat(x).st_size for x in sys.argv[1:]) / (1024*1024*1024)'