Summing file sizes

I was just curious about how to sum the total file size of a certain type of file. For instance:

$find . -name "*.aif"

will print out the paths to each .aif file. Instead of printing, how could one sum the total space used by all of the aif files? Thanks!

Try:

find . -name "*.aif" -ls | awk '{s+=$7}END{print s/(1024*1024)" Mbytes"}'
1 Like
find . -name "*.aif" -exec ls -l {} \; | awk ' { s+=$5 } END { printf "%d bytes\n", s } '
1 Like

Thanks for these explanations! They work excellently. I especially appreciate the nice formatting of the output in Mb.